Chad Dybdahl
Chad Dybdahl

Reputation: 195

JavaScript behavior differences between IE9 and older versions

EDITED: This issue appears in all modern browsers. Testing in Firefox, Chrome, and IE9 all behaves the same. So my JavaScript as shown below works ONLY in older IE versions.

I have a homegrown webhelp system that displays a single help page when it is first launched.

Each help page has a header div that contains a link to display itself in the context of a frameset (I know, I know).

Here is the JavaScript that generates the link:

<script type="text/JavaScript">
    $.noConflict();
        var frameurl="frameset.html?";
        var filename=location.href.substring(location.href.lastIndexOf('/') + 1,location.href.length);
        var truncate=location.href.substring(0, location.href.length-filename.length - 1);
        var subfolder=truncate.substring(truncate.lastIndexOf('/')+1,truncate.length)+"/";
        var newurl=frameurl+filename;
        document.write('<a href="' + newurl + '"><span class="bannerlink">Contents and Search</span></a>');
        </script>

Essentially, it constructs a URL based on the currently viewed page. So the resulting URL looks something like this:

frameset.html?About_account_demographics_xaa_insight.html

And then frameset.html contains the following script to interpret that string and display the correct page:

<script type="text/javascript">
function load() {
var test=(location.href.lastIndexOf('?'));
if (test>0)  {
    var page=location.href.substring(location.href.lastIndexOf('?') + 1,location.href.length);}
else {
var page="about_help.html"; 
     }
document.getElementById("contentwin").src=page; }
</script>

This works as intended in versions of IE up to and including IE8. I can get it to work in IE9 by enabling compatibility mode, of course.

In IE9 proper, the contentwin frame is blank. In all other browsers, the content appears as desired.

EDIT: Here is the frameset code:

 <frameset onload="load()" rows="52px,*" border=0 frameborder=0>
<frame border=0 frameborder=0 src="fis_hdr.html" name="header" scrolling="no"/>
  <frameset border=0 frameborder=0 cols="210px,*">
    <frameset border=0 frameborder=0 rows="50px,*">  
<frame border=0 frameborder=0 scrolling="no" name="searchwin" src="sub/searchbox.html"/>
 <frame marginwidth="5px" border=0 frameborder=0 name="indexwin" src="tocnav.html"/>

</frameset>
<frame border=0 frameborder=0 name="contentwin" src=""/>
 </frameset>
 </frameset> 

Upvotes: 1

Views: 1126

Answers (1)

epascarello
epascarello

Reputation: 207557

The solution is the fact you are referencing an id and there is no id with that value.

document.getElementById("contentwin").src=page; }  <-- you are referencing an id
<frame border=0 frameborder=0 name="contentwin" src=""/>  <-- There is no id here!

Add an id to the frame!

<frame border=0 frameborder=0 name="contentwin" id="contentwin" src=""/> 

Upvotes: 3

Related Questions