2

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

Please help me to fix it.

Thanks in advance.

Error: In 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

Error: In Mozilla

Load denied by X-Frame-Options: https://patents.google.com/?q=dsfsdfsd&embedded=true does not permit cross-origin framing.
Alireza
  • 83,698
  • 19
  • 241
  • 152
Maths RkBala
  • 2,097
  • 3
  • 16
  • 19

2 Answers2

4

The website https://patents.google.com 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.

Alberto Trindade Tavares
  • 8,288
  • 4
  • 31
  • 43
1

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.com/watch?v=KUh2O8HylUM.

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

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