当我在 iframe
中实现 patent search google
时,出现以下错误
>.
in a frame because it set 'X-Frame-Options' to 'sameorigin'.
document.getElementById("go_search").onclick = function() {
myFunction();
};
function myFunction() {
var patent_content = document.getElementById("patent_content").value;
var html_content = '<iframe crossorigin="anonymous" src="https://patents.google.com/?q=' + patent_content + '&embedded=true" height="200" width="300"></iframe>';
document.getElementById("result").innerHTML = html_content;
}
<h2>Google Patent Search</h2>
<form>
<p>Paste your content</p>
<textarea id="patent_content"></textarea>
<input type="button" id="go_search" value="go" />
</form>
<div id="result">
</div>
请帮我解决这个问题。
提前致谢。
错误: 在 Chrome 中
patent.html:1 Refused to display 'https://patents.google.com/?q=fghfhfghfg' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
patent.html:24 GET https://patents.google.com/?q=fghfhfghfg net::ERR_BLOCKED_BY_RESPONSE
错误: 在 Mozilla 中
Load denied by X-Frame-Options: https://patents.google.com/?q=dsfsdfsd&embedded=true does not permit cross-origin framing.
最佳答案
网站https://patents.google.com有一个 X-Frame-Options仅允许具有相同域的网站(即仅限其他 Google 网站)在 <iframe>
中呈现其页面。 .
所以你不能将他们的网站嵌入到你的网站中。浏览器看到响应 header 包含 X-Frame-Options: SAMEORIGIN
,他们会检查您的域并阻止 <iframe>
的渲染。这是一种需要避免的安全措施clickjacking .
关于javascript - 错误: in a frame because it set 'X-Frame-Options' to 'sameorigin' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45099755/