今天寫項目的時候遇到了一個問題,使用iframe嵌入網頁,瀏覽器報錯:Refused to display ‘url’ in a frame because it set ‘X-Frame-Options’ to ‘deny’。
網上查了一下原因:是SpringSecurity 防止惡意注入,所以設置了X-Frame-Options爲deny。如下圖:
解決問題,把這個X-Frame-Options設置爲disable。
解決辦法:找到SpringSecurity的配置文件,然後新增如下屬性:
//防止iframe
httpSecurity.headers().frameOptions().disable();
這個問題就可以解決了。
補充說明:X-Frame-Options的三個值的意思: