View Full Version : IE7 Won't load external JS

10-04-2008, 07:58 AM
I have a hide/show script in js which works fine in Firefox, but doesn't even show in Internet explorer. When I try to directly load the js file in Internet Explorer, I get an error

"Internet Explorer cannot download collapse.js.php from courses.mytwu.ca.

Internet Explorer was not able to open the Internet site. The requested site is either unavailable or cannot be found. please try again later."

Here is the file: https://courses.mytwu.ca/my/collapse.js.php

I'm currently using Firefox 3.0.1 and Internet Explorer 7.0.5730.11

Does anybody know why this would happen?

10-04-2008, 12:10 PM
Remove the .php suffix (which is for PHP files) and use only the .js suffix.

i.e. rename the file to collapse.js

10-04-2008, 07:19 PM
It's.php because it has php code in it which generates the javascript... So is ie7 not able to handle *.js.php filenames?

10-09-2008, 08:10 AM
I tried changing it to collapse.php, and it still didn't work in internet explorer. It still worked in firefox though.

I tried changing it to collapse.js, and it didn't work in internet explorer that time either. In firefox, the show/hide function still worked but the php scripts didn't run so the images for the buttons didn't show up (since their uri's weren't generated by php).

So Internet Explorer must not be liking something about the javascript itself. Can somebody read the code by clicking on the link in my first post, and see if they can spot anything suspicious?

10-09-2008, 12:19 PM
try embeding the code in the page with a valid image src or post the HTML the script uses

10-09-2008, 03:32 PM
Try setting the content type to text/plain and see if it makes a difference.


10-16-2008, 01:23 AM
I tried changing the content type to text/plain. That just made it stop working in both browsers. I'll try embedding the code later when I have time and see what happens

Bill Posters
10-16-2008, 09:15 AM
The use of php is a non-issue.
It's being served up correctly as text/javascript, so it's not going to be the problem.

I'd focus on the DOM methods used in the headercatid function.
Try swapping out hasAttribute and getAttribute methods for older DOM0 methods.


function headercatid(header) {
if (!header.id) {return false;}
var id = header.id;
var m = id.match(/cat\-header\-(\d+)/);
if (m === null) {return false;}
return m[1];

10-16-2008, 10:02 AM
Wow thanks Bill!

I made your suggested changes the buttons appear in IE7 and they work! =). And they still work in Firefox.

They are placed oddly though (bleeding of the edge of the h2 box so you can barely see them) but hopefully I'll be able to fix that with a little bit of CSS. Now my IE users will be happy too =P.

So is it just that IE doesn't support hasAttribute and getAttribute yet?