Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

Internet Explorer 5.5 Reloads Page Instead of Scrolling When You Click an Anchor Targeting a Different Frame


View products that this article applies to.

This article was previously published under Q274586

↑ Back to the top


Symptoms

Internet Explorer 5.5 may reload a page instead of scrolling when you click an anchor that targets a different frame. For example, assume that you have a Web page that contains two frames: an upper frame and a lower frame. The upper frame contains several hyperlinks that point to the anchors in the lower frame. When you click the hyperlinks in the upper frame, the lower frame is reloaded instead of being scrolled (as in earlier versions of Internet Explorer). If the lower frame captures the "onload" event to perform initialization, the problem is magnified.

↑ Back to the top


Workaround

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.

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


Keywords: KB274586, kbprogramming, kbprb

↑ Back to the top

Article Info
Article ID : 274586
Revision : 4
Created on : 1/29/2007
Published on : 1/29/2007
Exists online : False
Views : 306