Refused to display 'url' in a frame because it set 'X-Frame-Options' to 'deny'報錯

今天寫項目的時候遇到了一個問題,使用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的三個值的意思:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章