Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Need help with javascript code

    Problem is in website url names, that are generated automaticaly.
    1. www.mywebsite.com
    2. www.mywebsite.com/wallpapers/show/...
    3. www.mywebsite.com/wallpapers/browse_by_size/...
    4. www.mywebsite.com/categories/show/...

    I need to hide div section only in one type of pages (2 in the list).
    So there is the code that I need help with:
    Code:
    <script type = "text/javascript">
    function showMyDiv() {
    var url = window.location.href; 
    if (/(wallpapers)/i.test(url)) { // the word appears in the url
    document.getElementById("hide").style.display="none";
    }
    else {
    document.getElementById("hide").style.display="block";
    }
    }
    </script>

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    I assume (since you did not provide it) that you are running "showMyDiv()" on page load?
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,084
    Thanks
    80
    Thanked 4,552 Times in 4,516 Posts
    If you do it as you show, then the <div> will appear briefly and then get hidden.

    Wouldn't it be better to *START* with it hidden and then only show it if the URL does *not* contain "wallpaper"??

    If so, it's easy:
    Code:
    <html>
    <body>
    ...
    <div id="hide" style="display: none;">....</div>
    ...
    <script type="text/javascript">
    if (! /wallpapers/i.test(location.href) ) { 
        document.getElementById("hide").style.display="block";
    }
    </script>
    </body>
    </html>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    As I said I have problem with urls, so as you can see 2 and 3 have the same word in it:
    1. www.mywebsite.com
    2. www.mywebsite.com/wallpapers/show/...
    3. www.mywebsite.com/wallpapers/browse_by_size/...
    4. www.mywebsite.com/categories/show/...
    PROBLEM: I need to show DIV only in 2-url, which leads to wallpaper, while 3-url leads to wallpaper category.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,240
    Thanks
    203
    Thanked 2,554 Times in 2,532 Posts
    Code:
    if (/(wallpapers\/show)/i.test(url)) { // the words appears in the url
    Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. Everyone posting here wants help with his Javascript code. You can (and should) edit it to make it more meaningful.



    "A psychiatrist asks a lot of expensive questions that your wife asks for nothing." – Joey Adams
    Last edited by Philip M; 07-24-2012 at 09:29 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    mark1ra (07-24-2012)

  • #6
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Code:
    if (/(wallpapers\/show)/i.test(url)) { // the words appears in the url
    Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. Everyone posting here wants help with his Javascript code. You can (and should) edit it to make it more meaningful.



    "A psychiatrist asks a lot of expensive questions that your wife asks for nothing." – Joey Adams
    Thanks, next time I will write it properly.


  •  

    Posting Permissions

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