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!


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.

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.

Need Your Help

VS2015 debugging on remote machine, Connection always fails

visual-studio win-universal-app remote-debugging

When follow the tutorial Run Windows Store apps on a remote machine,Visual Studio 2015 can't connect to the remote debugging tools.