最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error : in a frame because it set 'X-Frame-Options' to 'sameorigin' - Stack Overflo

programmeradmin4浏览0评论

I got the following error when I implement patent search google in iframe.

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="/?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>

I got the following error when I implement patent search google in iframe.

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./?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>

Please help me to fix it.

Thanks in advance.

Error: In Chrome

patent.html:1 Refused to display 'https://patents.google./?q=fghfhfghfg' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
patent.html:24 GET https://patents.google./?q=fghfhfghfg net::ERR_BLOCKED_BY_RESPONSE

Error: In Mozilla

Load denied by X-Frame-Options: https://patents.google./?q=dsfsdfsd&embedded=true does not permit cross-origin framing.
Share Improve this question edited Jul 14, 2017 at 11:01 Alireza 105k27 gold badges277 silver badges173 bronze badges asked Jul 14, 2017 at 9:44 Maths RkBalaMaths RkBala 2,1953 gold badges20 silver badges22 bronze badges 2
  • Possible duplicate of: stackoverflow./questions/3102819/… – Ved Commented Jul 14, 2017 at 9:48
  • @ved I have tried something different. Kindly check my code... – Maths RkBala Commented Jul 14, 2017 at 9:50
Add a ment  | 

2 Answers 2

Reset to default 8

The website https://patents.google. has a X-Frame-Options that allows only websites with the same domain (i.e., other Google websites only) to render its page in an <iframe>.

So you cannot embed their website into yours. Browsers when see that the response header contains X-Frame-Options: SAMEORIGIN, they check your domain and block the rendering of the <iframe>. It is a security measure to avoid clickjacking.

I had this problem too, but all you have to do is grab the last bit of a youtube link. For example, in this link https://www.youtube./watch?v=KUh2O8HylUM.

KUh2O8HylUM - copy this and in the src="https://youtube./embed/here" as shown below.

<iframe src="https://youtube./embed/KUh2O8HylUM"
        width="560" height="315" frameborder="0" allowfullscreen>
</iframe>
发布评论

评论列表(0)

  1. 暂无评论