开发者

Stop location.hash of frame's parent from reloading page

I have a frameset with to frames left/right. The content of the frame left the one below. As you can see, I want to update the hash/fragment identifier of the left frame's parent (the uppermost window) location.

However, this leads to reloading the whole frameset in Safari/Chrome. In Firefox, the whole frameset is not reloaded, but the browsers displays "loading" continuously.

Background: The left frame shows a navigation. A click in an entry loads another HTML page in the right frame and should also update the hash in the location of the browser window so the user can bookmark pages.

How can I make this work?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Left</title>
开发者_如何学Python</head>
<body>

<script type="text/javascript" charset="utf-8">
  function go()
  {
    window.document.write('foo');  // replace document with 'foo'
    window.parent.location.hash = '#foo';
  }
</script>

<h1>Left</h1>
<p>
  <a href="#" onclick="javascript:go(); return false;">Go</a>
</p>

</body>
</html>


You might want to try changing:

onclick="javascript:go(); return false;"

...to something like:

onclick="void(javascript:go(););"


Instead of using window.parent.location.hash just try something like this:

JS:

function go()
{
  window.document.write('foo');  // replace document with 'foo'
}

HTML:

 <a href="#foo" onclick="go()">Go</a>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜