阻止IE刷新页面 - iframe _top

时间:2010-12-08 14:49:19

标签: internet-explorer iframe hash refresh

如何阻止IE更新页面?我希望它表现得像FF,SF& C.因为它是同一页面所以不应该上传...

父页:

<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <p>This is the parent page. I don't want this page to reload in IE when the link in the iframe is clicked, since it break our javascript. I only want the "hash" to change.</p>
    <iframe src="http://example.com/iframepage.html"></iframe>
</body>
</html>

iframe页面:

<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <p>This is the iframe page. The URL is the same as the parent page + anchorlink. When I klick this link in IE the page refresch and the javascript breaks. In FF, SF & C it doesn’t "refresh" page…</p>
    <a href="http://www.example.com/test.html#test1" target="_top">test1</a>
</body>
</html>

1 个答案:

答案 0 :(得分:-1)

为所有浏览器试用此代码

var src = document.getElementById("mydiv").getAttribute("src");

if (navigator.appName == "Microsoft Internet Explorer")  // ie iframe reload fix
    document.getElementById("mydiv").setAttribute("src","");

$SQuery(mydiv).setAttribute("src",src); // this will not save it in history ;)