Mike
Mike

Reputation:

IE 7 not displaying a simple JS Alert?

Try clicking on the "Print" button on the following page: (link removed - consensus is that everything was working fine and the problem was my setup) For debugging purposes, I've replaced a chunk of javascript with a simple alert("test"), and even that isn't showing up in IE7 for me. It works totally fine in Safari, FF (Mac and PC) and IE6, but for some reason it's not working in IE7. For your reference, the code in the button is this:

<a onclick="makeNewWindow()" href="#"><img src="/print.gif"/></a>

And the JS inside /newsletter/print.js is this:

function makeNewWindow() {
   alert("test");   
}

Can anyone help me understand if there's a way around this, or if this has something to do with the fact that I'm running "IE7 Standalone" via Parallels on my Mac? Any help is greatly appreciated.

Thanks, Mike

Upvotes: 2

Views: 13657

Answers (6)

LesFromWalden
LesFromWalden

Reputation: 1

The first answer posted - ie, use href='javascript:void(0);' instead of href='#'. In your case, use href='javascript:yourFunction();' and it should work. IE appears to give precedence to href over onclick (other browsers don't). Also, if you don't have an href, you get a page not found error.

Upvotes: 0

PhiLho
PhiLho

Reputation: 41152

It might not be the original issue, but since I had the same problem, I give my finding, it can be useful to somebody else.

In fact, I tested an HTML by just opening it from Windows Explorer, so I have a file:// URL in the address bar.
This works fine in all browsers, except Internet Explorer 7 (and maybe above).
In fact, when I opened this file in IE7, I got an alert about security issues with a local file with script. They got so many security breaches that they are overly protective...

It appeared that alert() is just deactivated in this local mode, and I couldn't find security settings to enable it (not searching too hard...).
I finally dropped the file in the www directory of my local Apache install (using WampServer 2 but other distributions are fine, probably), and opened it via http://localhost, and the behavior of alert() was OK there...

I also discovered that javascript:alert("Foo"); in the address bar is just totally deactivated, an infuriating "design" choice... it was just too convenient.

Upvotes: 2

Andrew G. Johnson
Andrew G. Johnson

Reputation: 26993

I'm guessing that you have an error with OTHER javascript code which is causing your browser to just ignore everything else.

Also you may want to change that code to ... onclick="makeNewWindow();return false" ... in order to avoid confusion

Upvotes: 3

hasen
hasen

Reputation: 166252

could be that it's caching an older version of the js file? try ctrl-F5

Upvotes: 3

user21582
user21582

Reputation: 190

Javascript is probably disabled in your particular setup of IE7. See this link how to enable it : http://www.tranexp.com/win/JavaScript-enabling.htm

Upvotes: 4

nickf
nickf

Reputation: 546243

Just tested it on IE7 Vista and it worked fine... Your code looks sound as well, so I think it might be an issue with your setup?

Upvotes: 5

Related Questions