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

Article translations Article translations
Article ID: 274586 - View products that this article applies to.
This article was previously published under Q274586
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

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.

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.

STATUS

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

REFERENCES

For additional information, see the following Microsoft Web sites:
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_navigator.asp

http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_event.asp

http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/a.asp

http://msdn.microsoft.com/workshop/Author/dhtml/reference/methods/scrollIntoView.asp
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
http://msdn.microsoft.com/ie/

http://support.microsoft.com/iep

Properties

Article ID: 274586 - Last Review: October 21, 2013 - Revision: 3.1
APPLIES TO
  • Microsoft Internet Explorer 5.5
  • Microsoft Internet Explorer 5.5
  • Microsoft Internet Explorer 5.5
  • Microsoft Internet Explorer 5.5
  • Microsoft Internet Explorer 5.5
Keywords: 
kbnosurvey kbarchive kbprb kbprogramming KB274586

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com