Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-17-2013, 02:45 PM   PM User | #1
Rudolf
New to the CF scene

 
Join Date: Oct 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rudolf is an unknown quantity at this point
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
Rudolf is offline   Reply With Quote
Old 02-17-2013, 03:35 PM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
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..
Logic Ali is offline   Reply With Quote
Old 02-17-2013, 07:51 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,101
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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">?
__________________

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..
Philip M is offline   Reply With Quote
Old 02-17-2013, 10:22 PM   PM User | #4
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Quote:
Originally Posted by Philip M View Post
That works. But surely it is <script type = "text/javascript">?
I'm sure you're right.
Logic Ali is offline   Reply With Quote
Old 02-17-2013, 10:49 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 02-18-2013, 08:34 AM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,101
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 02-18-2013, 08:51 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:59 AM.


Advertisement
Log in to turn off these ads.