...

View Full Version : how to stop NS4 from seeing script....



llizard
05-06-2004, 08:35 PM
First of all, I realize that NS4 is basically dead. However, there are still a few out there using it. I have cursor trail script on a validated doctype xhtml 1.0 Transitional (thanks to Liorean for that!) that is throwing out a javascript error for NS4.

I have done one of those @import url(style_insert.css); hacks to deal with some of NS4's vaguaries with CSS. The cursor trail CSS specs are inside .spanstyle. I placed
.spanstyle {visibility:hidden} in the stylesheet for NS4 to read and




.spanstyle {
visibility:visible !important;
overflow: hidden;
position:absolute;
top:-50px;
font-size:small;
font-weight:bold;
font-style:italic;
color:#30f;
font-family: 'Book Antiqua', 'Apple Chancery', serif;
}


in the stylesheet for the current browsers.

The cursor trail message shows up in NS4 anyway along with the javascript error message at the bottom of the page.

I tried applying the media="all" hack:



<script src="cursortrailhead.js" type="text/javascript" language="JavaScript" media="all"></script>


but then the page no longer validates.

Ideas?

Here is the actual page:
http://llizard.crosswinds.net/cwc/showhidecursortrail03may_strict.html

joh6nn
05-07-2004, 06:54 AM
having looked at the script, it seems to already have checks in place to determine whether NS4 is being used. since those don't seem to be working, and since i haven't got a copy of NS4 to test with, i think the SIMPLEST ( though certainly not the best ) solution would be the following:

<script>
if (!document.layers) {
document.write('<script src="cursortrailhead.js" type="text/javascript" language="JavaScript"></' + 'script>');
}
</script>

document.layers is not the best way to check for NS4, though. i'd recommend using a combination of window.navigator (http://javascriptkit.com/javatutors/navigator.shtml) properties to check and make sure that you've really got NS4.

generally speaking, i don't condone browser detection; i suggest object detection (http://developer.apple.com/internet/webcontent/objectdetection.html) instead. however, in this particular case, i don't think it's much of an issue.

brothercake
05-07-2004, 07:22 AM
If you use a language attribute at a version higher than ns4 understands then it won't parse the script:


<script language="javascript1.5" ... etc

But that limits you to XHTML Transitional, because the language attribute is gone from Strict.

jbot
05-07-2004, 10:32 AM
document.layers is not the best way to check for NS4

why not? it's way better than the navigator object, which can be spoofed by Opera.

document.layers is not supported by either IE or Ns6+/Moz, so surely it can only point to NN4.x! :confused:

i use this to check for NN4.x:


if (document.layers && !document.all && !document.getElementById) bNN4=true;

works a treat :thumbsup:

llizard
05-07-2004, 03:58 PM
having looked at the script, it seems to already have checks in place to determine whether NS4 is being used. since those don't seem to be working, and since i haven't got a copy of NS4 to test with, i think the SIMPLEST ( though certainly not the best ) solution would be the following:

<script>
if (!document.layers) {
document.write('<script src="cursortrailhead.js" type="text/javascript" language="JavaScript"></' + 'script>');
}
</script>


Yes, Joh6nn, the cursor trail script works in NS4 with doctype 4.0 Transitional but when I put it onto an xhtml page, it required a fix so that the script would work in NS7. The fix causes an error in NS4. I'm not sophisticated enough in Javascripting to figure out what to remove from the script so that NS4 won't even see it. (I've done a random hunt and peck removal system, using half-educated guesses - ending up only in failures)

But your recommendation to use a browser detection script to call up the cursor trail works perfectly. I'm not a big fan of browser detection either but I think it's probably safe to use this one in this case. I made this small change:



language="JavaScript"><\/script>');



Many thanks for this solution.

brothercake
05-07-2004, 05:53 PM
why not?
Because the layers object doesn't always exist- it only exists in the <head> section of a page if the rendering surface already contains a document. This means that if you sniff for document.layers in a script in the head section, and the page is the first page to be viewed in that browser session, the test will fail.

llizard
05-07-2004, 06:15 PM
Because the layers object doesn't always exist- it only exists in the <head> section of a page if the rendering surface already contains a document. This means that if you sniff for document.layers in a script in the head section, and the page is the first page to be viewed in that browser session, the test will fail.

I'm sorry but I'm having a lot of difficulty understanding what you are saying there. Under what circumstances would the page be the first page to be viewed in the browser? I am presently using NS4 and opened the link to the cursortrail page with the browser detection script to stop it from rendering in NS4 (http://llizard.crosswinds.net/cwc/showhidecursortrail03may_strict.html) in a new window. That means that it was the first page to be viewed in that browser session, doesn't it?

(As expected, the cursor trail script did not run in NS4 and no javascript errors occurred.)

llizard
05-07-2004, 07:02 PM
Brothercake's concerns that the browser detection script might not be the answer were hounding me. So I did some more hunting and pecking and I think I have blundered upon a tidier solution!



for (i=0; i<message.length; i++) {
if (document.getElementById) {
var thisspan = document.getElementById("span"+i).style;
} else {
var thisspan = eval((document.getElementById)?"document.span"+i:"span"+(i)+".style");
}
if (thisspan.posLeft) {
thisspan.posLeft=xpos[i]+'%';
thisspan.posTop=ypos[i]+'%';
}
if (!thisspan.posLeft) {
thisspan.left=xpos[i]+'px';
thisspan.top=ypos[i]+'px';
}
}
}
var timer=setTimeout(makebanner,30);
}
if (document.layers) {
message=''
}

eval((document.getElementById)? was eval((document.layers)? in the original version.

Having done this, have I also eliminated early versions of IE from seeing the script or will there be an error in ancient versions of IE? (The only IE I have - and that is under duress - is IE6.) I'm wondering if I need to change the empty message area to something like:



if (document.layers || document.all) {
message=''
}

The new version of the page now works as expected on Win2K in NS4, NS7, firefox, IE6 and Opera7.

new version of page:
http://llizard.crosswinds.net/cwc/showhidecursortrail07may_strict.html



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum