开发者

JavaScript history control targeted at iFrame affecting parent

开发者 https://www.devze.com 2023-01-08 13:58 出处:网络
I\'ve just noticed that my JavaScript history control targeted at a iFrame is affecting the parent. The code is:

I've just noticed that my JavaScript history control targeted at a iFrame is affecting the parent. The code is:

document.getElementById('iframeid').contentWindow.history.back(-1);
document.getElementById('iframeid').contentWindow.history.forward(-1);

It works fine, until there is nothing to go back or forward in the iframe, where then it will affect the parent frame moving that backwards and forwards, this is occurring on all major browsers, safari, oper开发者_C百科a, chrome, firefox, ie 6 7 8.

Anyone know how to stop it?


Check the history object's length first:

if (document.getElementById('iframeid').contentWindow.history.length)
{
   // your code....
}

The condition will run only when there is something for the history object to navigate around.

0

精彩评论

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