To work around this behavior, the Web page author can modify the upper frame by replacing the typical hyperlink with "anchor.scrollIntoView". The following sample page demonstrates this method:
Original page:
...
<head>
<base target="bottomframe">
</head>
...
<a href="frame2.htm#2.1">1-2.1</a>
...
Modified page:
...
<head>
<script lanaguage="JScript">
function ScrollTo(name)
{
top.bottomframe.document.anchors.item(name).scrollIntoView();
}
</script>
</head>
...
<a href="javascript:ScrollTo('2.1')">1-2.1</a>
...
Or, with a frameset declared as:
<frameset cols=50%,* id=frame1 name=frame1>
<frame src="left_toc2.htm" id="left" name="left"></frame>
<frame src="right_toc2.htm" id="right" name="right">
</frameset>
The left frame could navigate to an anchor by using the following code:
<A href="right_toc.htm#second" target="right" onclick="handle_click()">Second</A>
<script language=javascript>
function handle_click() {
var user_agent = window.navigator.userAgent
var msie = user_agent.indexOf ( "MSIE " )
if ( msie > 0 ) {
event_element = window.event.srcElement;
while (event_element.tagName != 'A') {
event_element = event_element.parentElement;
}
myelement = event_element.href;
myhash = myelement.substring ( myelement.indexOf("#")+1, myelement.length);<BR/>
parent.right.document.all(myhash).scrollIntoView();
window.event.returnValue = false;
}
else return true;
}
</script>
This script code functions as follows:
- Obtain the user agent string to check for Internet Explorer as the browser.
- Retrieve the source element for the click event.
- Make sure that the source element is an Anchor tag. If it is not, retrieve the source element's parent element. This handles cases in which the text of the anchor is wrapped in a Font tag.
- Parse the Href tag of the Anchor tag to remove the hash location.
- Access the other frame and use scrollIntoView on the hash that was parsed.
- Return False from the event. This prevents the anchor from navigating as well (because the code has handled the event).
- The Else statement catches all other browser types and allows regular navigation through the Href tag.