开发者

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 relo开发者_开发百科ad 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜