Enjoy an ad free experience by logging in. Not a member yet?
Register .
02-17-2013, 02:45 PM
PM User |
#1
New to the CF scene
Join Date: Oct 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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
02-17-2013, 03:35 PM
PM User |
#2
Regular Coder
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 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 ..
02-17-2013, 07:51 PM
PM User |
#3
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,101
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Quote:
Originally Posted by
Logic Ali
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">?
__________________
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.
Last edited by Philip M; 02-17-2013 at 07:54 PM ..
02-17-2013, 10:22 PM
PM User |
#4
Regular Coder
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 Posts
Quote:
Originally Posted by
Philip M
That works. But surely it is <script type = "text/javascript">?
I'm sure you're right.
02-17-2013, 10:49 PM
PM User |
#5
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 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.
02-18-2013, 08:34 AM
PM User |
#6
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,101
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Quote:
Originally Posted by
Old Pedant
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.
02-18-2013, 08:51 PM
PM User |
#7
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Quote:
Originally Posted by
Philip M
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.
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 09:59 AM .
Advertisement
Log in to turn off these ads.