Forum Moderators: phranque

Message Too Old, No Replies

Javascript

how to get it working for all browsers

         

specter

8:54 am on Jul 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hello,

I have that script (javascript)to get blinking text on my pages:

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

window.onerror = null;
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS4 = (bName == "Netscape" && bVer >= 4);
var IE4 = (bName == "Microsoft Internet Explorer"
&& bVer >= 4);
var NS3 = (bName == "Netscape" && bVer < 4);
var IE3 = (bName == "Microsoft Internet Explorer"
&& bVer < 4);
var blink_speed=800;
var i=0;

if (NS4 ¦¦ IE4) {
if (navigator.appName == "Netscape") {
layerStyleRef="layer.";
layerRef="document.layers";
styleSwitch="";
}else{
layerStyleRef="layer.style.";
layerRef="document.all";
styleSwitch=".style";
}
}

//BLINKING
function Blink(layerName){
if (NS4 ¦¦ IE4) {
if(i%2==0)
{
eval(layerRef+'["'+layerName+'"]'+
styleSwitch+'.visibility="visible"');
}
else
{
eval(layerRef+'["'+layerName+'"]'+
styleSwitch+'.visibility="hidden"');
}
}
if(i<1)
{
i++;
}
else
{
i--
}
setTimeout("Blink('"+layerName+"')",blink_speed);
}
// End -->
</script>

it doesn't work for Firefox.
Could I modify it in a simple way in order to get that result?

As I don't know at all javascript I need your help

thanks in advance

sincerely

rocknbil

11:05 am on Jul 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wow specter that script is really OLD, I mean like older than ME and that's saying something!

:-)

Your question was "simple way" and the answer is no, it needs to be scrapped. A key weak point (among many,)

if (NS4 ¦¦ IE4) {

Note that it's saying "if Netscape 4 or IE 4." No accomodation for FireFox, which didn't exist at the time of this script, which is weak point 2, building a script that relies on a browser identification to do anything at all.

Try this. I've no idea if it will work and am too tired to test it at the moment, but it stands a better chance than that. :-) Note how it just looks for the function we need to ID the "layer," getElementById.

For this to work the divs must have an ID, not just a name:

<div name="mydiv" id="mydiv">
Blinkme
</div>

<script type="text/javascript">

<!--
var blink_speed=800;
var i=0;

function Blink(layerName){
if (document.getElementById) {
var obj = document.getElementById(layerName);
if(i==0){ obj.style.visibility="visible"; }
else { obj.style.visibility="hidden"; }
}
if(i<1) { i++; }
else { i--; }
setTimeout("Blink('"+layerName+"')",blink_speed);
}
//-->
</script>

If it doesn't work, a wiser one than I will show the error of my ways. :-)

specter

2:44 pm on Jul 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks, but it doesn't work...

rocknbil

6:02 pm on Jul 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<sigh> Of course it does. I'm awake now. :-) What event is starting the blink? I tested the below in both IE and FF. Surprised myself, it actually does work. Copy, paste, test . . .

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
<!--
var blink_speed=800;
var i=0;

function Blink(layerName){
if (document.getElementById) {
var obj = document.getElementById(layerName);
if(i==0){ obj.style.visibility="visible"; }
else { obj.style.visibility="hidden"; }
}
if(i<1) { i++; }
else { i--; }
setTimeout("Blink('"+layerName+"')",blink_speed);
}
//-->
</script>
</head>

<body>
<div id="wth"><p><a href="#" onClick="Blink('blinkme'); return false;">Click me only if it isn't blinking already.</a></p></div>

<div id="blinkme">
Blinkme
</div>

<script type="text/javascript">
// For the blink to work, both the function and the div that blinks
// has to exist before you begin acting on them. This is why this is at
// the bottom and not in body onLoad.

Blink('blinkme');

</script>

</body>
</html>

rocknbil

6:12 pm on Jul 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Specter did you try this last solution? Working for you?