Results 1 to 6 of 6

Thread: Use window.location.href to hide .banner

  1. #1
    Join Date
    Jul 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Use window.location.href to hide .banner

    How can I use window.location.href to hide .banner when the url= someurl.com/hidebannerpage.aspx?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Here is what I am working with;

    Code:
    <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>

  4. #4
    Join Date
    Jul 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Why doesn't this work?

  5. #5
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    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.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    <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>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •