PDA

View Full Version : Use window.location.href to hide .banner



jasemhi
07-19-2008, 03:22 AM
How can I use window.location.href to hide .banner when the url= someurl.com/hidebannerpage.aspx?

jscheuer1
07-19-2008, 03:53 AM
Please post a link to the page on your site that contains the problematic code so we can check it out.

If this has to do with ads that are being put on your page as part of some hosting package deal (or something similar) you have, it is against the policy of this forum to help people avoid fulfilling the terms of service of their host.

jasemhi
07-19-2008, 04:24 AM
Here is what I am working with;


<html>
<body>

<script type="text/javascript">
z=window.location.pathname;

document.write(z); // result is /js/tryit_view.asp


if(z=="/js/tryit_view.asp")
{
document.getElementById('banner').style.display = 'none';
}
else
{

}
</script>

<div id="banner" style="display:block"><h3>This banner is removed if specific pathname appears in url.</h3></div>

jasemhi
07-19-2008, 02:34 PM
Why doesn't this work?

blm126
07-19-2008, 04:15 PM
Are you sure you want getElementById? You said you wanted ".banner" which looks like a class to me. Without seeing the page in question it is hard to help.

jscheuer1
07-19-2008, 05:08 PM
The script looks fine, except for one thing, and possibly another. The 'deal breaker' is that at the time that it executes, there is no element by the id banner. The other possible problem is the empty else. If there is no else, there shouldn't even be the else statement or its empty braces. I'm not sure if that one would cause an error, but it probably would in some browsers.

Try:


<html>
<body>
<div id="banner"><h3>This banner is removed if specific pathname appears in url.</h3></div>
<script type="text/javascript" defer="defer">
var z=window.location.pathname;
document.write(z); // result is /js/tryit_view.asp
if(z=="/js/tryit_view.asp")
document.getElementById('banner').style.display = 'none';
</script>