views:

213

answers:

6

http://home.earthlink.net/~benfranq/Sudoku.html

Perhaps somebody can tell me why it doesn't work in Internet Explorer

In other browsers, it seems to work fine.

I've tried adding semicolons to every line, but it still doesn't work.

This isn't my page, a friend asked me to figure out why it isn't working in IE but ok in other browsers. I'm moving it to my server since he won't allow me ftp to his server. Anyways, I'll post the new link with my semicolon changes right shortly.

+2  A: 

First guess: you have to end your lines with semi-colons

Mike Robinson
+1 - Always use `;`
Russ Cam
That was my first thought too, but it still didn't work after making that change.
hmcclungiii
+3  A: 

Semicolons

I don't think it's the only reason, but you should probably be ending each statement with a semicolon. JavaScript will let you get away without doing this sometimes, but it's always a good practice just to do it anyway.

Global/Window Scope

function hints(){
   for(c=0;c<N4;c++)if(status[c]==" "){  // unsolved cell 
      if(ruleCell(c)>0){ high(c) ; continue }                       
   }
}

Do you want to be manipulating c from within hints? Here, you'll be manipulating it in the global scope.

setAttribute('onclick')

IE misbehaves when doing elem.setAttribute("onclick",...), instead try using the event handling model. Here's a section on Wikipedia about Microsoft-Specific DOM Event handling.

JasonWyatt
As it works fine in other browsers, would that really be the problem?
hmcclungiii
Maybe not, but I added a section about setAttribute which is actually particular to IE
JasonWyatt
+1: Registering events in IE is different from most other browsers.
Joel Potter
The setAttribute calls were the culprit, but I've got to go with the other post for the answer. +1 though.
hmcclungiii
A: 

I think its because the first line is commented. When I see view source, the javascript line breaks are gone and therefore the entire javascript code is interpreted as a comment.

My suggestion: try removing the commented code or try block comments (/* */)

I copy pasted the source to my local machine, converted the // to /**/ and it seems to work (i admit, i just saw that things were better. I did not test).

Generally: If the javascript is compressed, by removing unnecessary spaces and new lines, avoid // comments as much as possible

(but if some program (the webserver?) is compressing javascript by removing unnecessary whitespaces shouldn't it also remove the comments?)

EDIT: To clarify: When I did view source in IE, I saw the javascript as a single looong line. In IE8's in-built source viewer (how do you call that?) and also when I copy pasted to Notepad

When I did view-source in Safari (Mac), the javascript was properly in different lines.

So:

  1. no javascript compressing going on here as I mentioned before.

  2. I suspect line endings. Do you develop on a non Windows machine, or is the editor on your windows machine configured to have a different line ending? (CR in place of CR/LF)

(anyway first try removing commented code to be sure. And then think about line endings)

Nivas
A: 

try to use different variables names. for some reason IE has restrictions about using some variables names like class or msie. I made a list and will share it soon :)

Anas Toumeh
+1  A: 

There are three problems.

  1. The elem.setAttribute("onclick",...) issue that JasonWyatt identified,

  2. The javascript uses square bracket notation to index the characters in a string. Use .charAt() instead.

  3. The elem.setAttribute("class",...) should be elem.className = ...

Alohci
+1  A: 

After running this through IE8's debugger (Press F12, it's actually a nice tool), I found the problem: IE8 is not treating your strings as an array of characters.

You're storing puzzle (and solution, among other things) as a string. In chrome/firefox, solution[2] will return the 3rd character in that string. However, in IE8, it returns undefined. The workaround is to use solution.charAt(2);

I also took the liberty of removing setAttribute calls and instead I'm setting the properties directly.

You can find the fixed code here (which works in IE8): http://pastebin.org/51648

Matt
Thanks, that was exactly what I needed.
hmcclungiii