Script works IE but not Opera. Why?

Forums » General Opera topics » User JavaScript

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

3. June 2010, 20:01:37

Script works IE but not Opera. Why?

I was wondering if any body could tell me what have I done wrong that this script only works with Internet Explorer browser but not the latest Opera browser.
Thanks in advance...
<script LANGUAGE="JavaScript1.2" type="text/javascript1.2">
//this example only seems to work in the Internet Explorer browser.
where = prompt("Where do you want to go today? Netscape, Microsoft, Yahoo or other?");
switch (where) {
case "Netscape" :
        window.location="http://www.netscape.com/";
        break;
    case "Microsoft" :
        window.location="http://www.microsoft.com/";
        break;
case "Yahoo" :
        window.location="http://www.yahoo.com/";
        break;
default :
        window.location="http://www.mobilestimulus.com/";
}
</script>

3. June 2010, 20:29:50

Vectronic

... ... ...

Posts: 2538

If it's not working at all, then there's something really wrong...

When I tested, it worked fine... however I also didn't use any specific JS versions, just:

<script type="text/javascript">
</script>

But you have to remember that it's case sensitive, so if you type in "microsoft" it won't find a match, you have to type in "Microsoft".

You could do something like:

var where = prompt("Where do you want to go today? Netscape, Microsoft, Yahoo or other?").toLowerCase();
switch (where) {
case "netscape":
...

That way if the user types in "microsoft", "Microsoft", "MICROSOFT" etc... it doesn't matter.

4. June 2010, 02:56:40

Thankyou. When I changed it to:
<script LANGUAGE="JavaScript" type="text/javascript">

It started working. But that doesn't answer why

<script LANGUAGE="JavaScript1.2" type="text/javascript1.2">


doesn't display the prompt at all.

4. June 2010, 03:17:42

Vectronic

... ... ...

Posts: 2538

Presumably because one or more of the following:
1. I don't think the "type" attribute accepts a version, it's always just "javascript"
2. JavaScript 1.2 support may have been dropped
(it's 13 years old, so Opera might just avoid it, other browsers probably just ignore the 1.2)
3. Something else in the document (DocType, etc) doesn't allow for it.
4 Unknown...lol

Check the Error Console in Opera (Tools - Advanced - Error Console) it should say something about it.

4. June 2010, 03:35:32

This script doesn't seem to work as well.
<html>
<head>
<title>Descriptive Links</title>
<script LANGUAGE="JavaScript" type="text/javascript">
function describe(text) {
    window.status = text;
    return true;
}
function clearstatus() {
     window.status="";
}
</script>
</head>
<body>
<h1>Descriptive Links</h1>
<p>Move the mouse pointer over one of
these links to view a description:</p>
<ul>
<li><a HREF="order.html"
    onMouseOver="describe('Order a product'); return true"
    onMouseOut="clearstatus()">
Order Form</a>
</li>
<li><a HREF="email.html"
    onMouseOver="describe('Send us a message'); return true"
    onMouseOut="clearstatus()">
Email</a>
</li>
<li><A HREF="complain.html"
    onMouseOver="describe('Insult us, our products, or our families'); return true"
    onMouseOut="clearstatus()">
Complaint Department</a>
</li>
</ul>
</body>
</html>

4. June 2010, 04:11:19

Vectronic

... ... ...

Posts: 2538

Because the normal status message (for the links) overrides the manual one... if you add the describe() to the LI's it works except when you mouse-over the links, this isn't an Opera issue... all browser *should* behave like that (and they all do except IE), if you want to have a description for a link use the "title" attribute, like:
< a href="order.html" title="Order a product">Order Form</a >

Which will show a tooltip with the message.

If you want to avoid that you would probably have to use another element type, like a span, then have the "onclick()" event go to the URL (window.location = url), or you can do something really ugly like have a JavaScript loop and try and force the message to be there...but don't do that.

4. June 2010, 05:56:34

Frenzie

Posts: 15547

Originally posted by mobilestimulus:

<script LANGUAGE="JavaScript1.2" type="text/javascript1.2">


I think IE is parsing that despite the TYPE value, not because. Also see this test I wrote a while ago
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Quick and Very Dirty Javascript Version Test</title>
</head>
<body> 
<script type="application/javascript">
function dirty(type) {document.write(type+'
');}
</script>

<script language="javascript1.5">dirty("lang-1.5");</script>
<script language="javascript1.6">dirty("lang-1.6");</script>
<script language="javascript1.7">dirty("lang-1.7");</script>
<script language="javascript1.8">dirty("lang-1.8");</script>
<script language="javascript1.8.1">dirty("lang-1.8.1");</script>
<script language="javascript1.9">dirty("lang-1.9");</script>
<script language="javascript2.0">dirty("lang-2.0");</script>

<script type="application/javascript;version=1.5">dirty("1.5");</script>
<script type="application/javascript;version=1.6">dirty("1.6");</script>
<script type="application/javascript;version=1.7">dirty("1.7");</script>
<script type="application/javascript;version=1.8">dirty("1.8");</script>
<script type="application/javascript;version=1.8.1">dirty("1.8.1");</script>
<script type="application/javascript;version=1.9">dirty("1.9");</script>
<script type="application/javascript;version=2.0">dirty("2.0");</script>
</body>
</html>
The DnD Sanctuary — a safety net for My Opera's demise.

Forums » General Opera topics » User JavaScript