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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Script that shows div on page when page itself is accessed from weblink only

    Hi all!

    This request may sound a bit confusing, but I am looking for a script that will show a certain div on a page, if the user has accessed that particular page from another website. However, I would like the div to be hidden if the user is accessing that page directly e.g. through his favorites, type-in in browser or via an email. Does anyone know where I can find it?

    Thanks in advance.

    M

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Try:
    Code:
    <script type='text/javascript'> /* Must be positioned BELOW 'myDiv' */
    
    document.getElementById( 'myDiv' ).style.display = ( document.referrer ? 'block' : 'none' );
    
    </script>
    Last edited by Logic Ali; 02-17-2013 at 10:22 PM.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Logic Ali View Post
    Try:
    Code:
    <script type='text.javascript'> /* Must be positioned BELOW 'myDiv' */
    
    document.getElementById( 'myDiv' ).style.display = ( document.referrer ? 'block' : 'none' );
    
    </script>
    That works. But surely it is <script type = "text/javascript">?
    Last edited by Philip M; 02-17-2013 at 07:54 PM.

    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.

  • #4
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by Philip M View Post
    That works. But surely it is <script type = "text/javascript">?
    I'm sure you're right.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    If you want to support people who have javascript disabled, then decide whether you want the <div> to be visible or not by default.

    If you want it to be invisible when JS is disabled, then be sure to specify
    Code:
    <div id="myDiv" style="display: none;">
    (If you want it visible when JS is disabled, do nothing. It will be.)
    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.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by Old Pedant View Post
    If you want to support people who have javascript disabled, then decide whether you want the <div> to be visible or not by default.

    If you want it to be invisible when JS is disabled, then be sure to specify
    Code:
    <div id="myDiv" style="display: none;">
    (If you want it visible when JS is disabled, do nothing. It will be.)
    Well, then it is hidden/visible whether they have come from another website or not.

    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.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Quote Originally Posted by Philip M View Post
    Well, then it is hidden/visible whether they have come from another website or not.
    Yes, but at least the state has a *KNOWN* default. Better than not knowing what will happen if JS is disabled. It's likely a very minor point.
    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.


  •  

    Posting Permissions

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