1

I'm new to java script and I'm trying to run a Java Script that will cycle through several websites every X seconds automatically. It should go through all the 4 sites and go back to the beginning. For some reason only some of the sites are not displaying. Only Ask.com and Dogpile is displaying. Here's my code below. Could someone help me. Thank you in advance.

var frames = Array('http://www.google.com/', 15,
    'http://www.yahoo.com/', 37,
    'http://www.ask.com/', 12,
    'http://www.dogpile.com/', 14);
var i = 0, len = frames.length;
function ChangeSrc()
{
  if (i >= len) { i = 0; } // start over
  document.getElementById('frame').src = frames[i++];
  setTimeout('ChangeSrc()', (frames[i++]*1000));
}
window.onload = ChangeSrc;
<iframe src="" name="frame" id="frame" width="100%" height="100%"></iframe>
  • 3
    Possible duplicate of [Overcoming "Display forbidden by X-Frame-Options"](https://stackoverflow.com/questions/6666423/overcoming-display-forbidden-by-x-frame-options) – Van Peer Oct 04 '17 at 05:37

1 Answers1

0

Check the console log. It says

Refused to display 'https://www.google.co.in/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.

This means that 'http://www.google.com' and 'http://yahoo.com'send an "X-Frame-Options: SAMEORIGIN" response header. This header would prevent the browser from displaying iFrames that are not hosted on the same domain as the parent page.

However, apparently, the other two websites do allow cross-domain framing, hence they show up in your iFrame

Manav
  • 1,357
  • 10
  • 17
  • 1
    Thank you very much!! that answered my problem. Sorry new to the site. How do i tagged my question as solved? and do i need to give you points or something for helping me out? – titanium kit Oct 06 '17 at 08:31
  • You just need to check the green tick-mark below the votes on the answer :) – Manav Oct 06 '17 at 09:11