Click to See Complete Forum and Search --> : Make script work on a specific page


florida
02-12-2003, 06:38 AM
In my javascript I am using this to hide a form object in my page using Netscape 4. It works great on that page but creates problems on other pages which use the javascipt. Anyway to make this condition work on just the one page (called mypage.html)?

How I create layer in mypage.html

<ilayer id="l1">
<form action="form.html">
<input type="text">
</form>
</ilayer>

Here is how I am using it located in a seperate javascript file, which works great on mypage.html

if(document.layers)
{
document.l1.visibility = "hide";
}

Now I need to make it where it only effects "mypage.html" so other pages that are using the javascript will not get this part of the javascript.
I tried this but not working:

if(document.layers) == 'mypage.html'
{
document.l1.visibility = "hide";
}

gil davis
02-12-2003, 06:56 AM
Originally posted by florida
I tried this but not working:

if(document.layers) == 'mypage.html'
{
document.l1.visibility = "hide";
} That's pretty funny!


if (window.location.href.toLowerCase().indexOf("mypage.html") != -1) {
if(document.layers) == 'mypage.html'
{document.l1.visibility = "hide";}
}

florida
02-12-2003, 07:18 AM
Thanks for the answer. I am not sure what all this is doing?? -1 in Javascript means what?

(window.location.href.toLowerCase().indexOf("mypage.html") != -1)

pyro
02-12-2003, 07:26 AM
Originally posted by gil davis

if (window.location.href.toLowerCase().indexOf("mypage.html") != -1) {
if(document.layers) == 'mypage.html'
{document.l1.visibility = "hide";}
} Shouldn't that be

if (window.location.href.toLowerCase().indexOf("mypage.html") != -1) {
if(document.layers)
{document.l1.visibility = "hide";}
}

??

And, what this line if (window.location.href.toLowerCase().indexOf("mypage.html") != -1) is doing is detecting if your current location has "mypage.html" in it somewhere.

linnie
02-12-2003, 07:41 AM
Originally posted by florida
I am not sure what all this is doing?? -1 in Javascript means what?

The -1 in JavaScript means that the indexOf() method didn't find the search string in the string that's being searched.

Lin