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.
精彩评论