James Bagley

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJames Bagley
ToMe
SubjectConflicts
Date29 July 2005 10:43
Hi,
Can you help me?
Iam having trouble put more than one javascript in my page. You have one
javascript on your page that works fine. You add another javascript and one,
or both, stop working.
Can you help.
Here's the script, can i add more than 1 of these to my page.

[Ed. NOTE: I did not write this script, and I do not recommend its use - it
is included here only because this was the email that was sent to me]

<table border="0" width="280" id="myexample" style="border:5px solid green">
<tr>
<td>This is a great attention getting script!<br>However NS does not
recognize it<br>All they will see is plain text<br>You can add links like
this <a href="http://www.example.com">Foo</a></td>
</tr>
</table>

<script language="JavaScript1.2">
<!--

/*
© 2000 The Abusive_Poet
Rights Registered and Reserved
Please respect my work
*/

function flashit(){
if (!document.all)
return
if (myexample.style.borderColor=="green")
myexample.style.borderColor="red"
else
myexample.style.borderColor="green"
}
setInterval("flashit()", 500)
//-->
</script>
Many Thanks
James Bagley
FromMe
ToJames Bagley
SubjectRe: Conflicts
Date29 July 2005 13:43
James,

Urgh, what an ugly script! Not only is it restricted to only one element, it
also works only in IE and Opera. I suggest this rewrite, it uses classes
instead, so you can apply to class to as many elements as you want:

<style type="text/css"><!--
/* normal style here */
.flashMe { border: 5px solid green; }
/* 'flash' style here */
.flashMeOn { border: 5px solid red; }
--></style>

<table border="0" width="280" class="flashMe">
<tr>
<td>Foo</td>
</tr>
</table>

<div class="flashMe">Bar</div>

... Now put this just before the </body> tag...

<script type="text/javascript"><!--
var elFlLst = [];
var AllEls;
if( document.getElementsByTagName ) {
 AllEls = document.getElementsByTagName('*');
}
if( document.all && !elFlLst.length ) {
 //length check is to compensate for IE 5.0 '*' bug
 AllEls = document.all;
}
for( var i = 0; i < AllEls.length; i++ ) {
 if( AllEls[i].className && AllEls[i].className.match(/\bflashMe\b/) ) {
  elFlLst[elFlLst.length] = AllEls[i];
 }
}
function flashit() {
 for( var i = 0; i < elFlLst.length; i++ ) {
  if( elFlLst[i] && elFlLst[i].className.match(/\bflashMe\b/) ) {
   elFlLst[i].className = elFlLst[i].className.replace(/\bflashMe\b/,'flashMeOn');
  } else {
   elFlLst[i].className = elFlLst[i].className.replace(/\bflashMeOn\b/,'flashMe');
  }
 }
}
setInterval("flashit()", 500);
//--></script>


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromJames Bagley
ToMe
SubjectRe: Conflicts
Date1 August 2005 10:29
Thanks very much for this script. It works fine now.
Thanks again for your help.
James Bagley
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.