Sinal
Sinal

Reputation: 1165

Refresh iframe in javascript

I tried to run a line of code as the following:

document.getElementById('frame0').contentDocument.location.reload(true); to force iframe to refresh or reload but I got the error like "permission denied" in firefox. Does anyone know why? and help to offer a solution? Thanks!

Upvotes: 0

Views: 1370

Answers (2)

bobince
bobince

Reputation: 536745

You can't reload a document that comes from a different hostname, due to the Same origin policy, which applies in all browsers.

You would have to remove the iframe from the page and replace it with a new one:

var iframe= document.getElementById('frame0');
var newiframe= document.createElement('iframe');
newiframe.src= iframe.src;
iframe.parentNode.replaceChild(newiframe, iframe);

However this will load the original src of the <iframe>, which won't be the same as the current location if the user has navigated the page since.

Upvotes: 0

Thariama
Thariama

Reputation: 50840

It is probably because of crossdomain issues - looks like your iframes content is from another domain as your mainframe (from which you run your js code). FF is very restrictive concerning crossdomains.

Upvotes: 1

Related Questions