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 01-08-2012, 04:16 AM   PM User | #1
cub
New Coder

 
Join Date: Jan 2012
Posts: 10
Thanks: 3
Thanked 0 Times in 0 Posts
cub is an unknown quantity at this point
visitor welcome message

Hi all new guy on the block here,

I've got a website, and I want to add a welcoming message which hovers on a certain part of the page which only loads for the visitor for the first time they login, and won't again(presumably cookies used). And says something like "adjust your settings here.." I don't want it to be an external popup but something that loads on the page in a certain area, defined by me (PX-pixle reference)

I think i nutted something out in a bit of PHP, this is what i've got so far
PHP Code:
<?php
    
if (firstLogin()){
        
genSpecial(***load jquerie or css etc***);
    }
    else{
        
genRegular();
    }
?>
can anyone help me figure out how to make this all work and load a box from jquerie or something similar? thanks
David

Last edited by cub; 01-08-2012 at 05:56 AM.. Reason: not clear enough
cub is offline   Reply With Quote
Old 01-08-2012, 09:12 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Here you are:-

Code:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else {var expires = ""}
document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function eraseCookie(name) {
createCookie(name,"",-1);
}
</script>
</head>

<body>
<div id = "message"></div>

<script type="text/javascript">
if(!readCookie('beenHereBefore')) {
document.getElementById("message").innerHTML = "You have not visited this site before.";
createCookie('beenHereBefore', 'beenHereBefore', 365);  // 365 days persistence
}
else {
document.getElementById("message").innerHTML = "You have visited this site before.";
}

</script>

</body>
</html>
You could as an alternative have a <div> containing the message which is initially set to style="display:none", changed to style.display="block" if the cookie is not found (or vice-versa). You will need to position and style the <div> using css, and include a way of dismissing the message after it has been displayed (user clicks something). What are the settings to be adjusted?

Bear in mind that many people erase their cookies at frequent intervals - sometimes daily, so you cannot be sure that the user is in fact a new visitor.

That's the kind of song all young kids know, even if they have not heard it before. Steve Wright Show, BBC Radio2.
__________________

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; 01-08-2012 at 10:36 AM.. Reason: Typo
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
cub (01-08-2012)
Old 01-08-2012, 10:43 AM   PM User | #3
cub
New Coder

 
Join Date: Jan 2012
Posts: 10
Thanks: 3
Thanked 0 Times in 0 Posts
cub is an unknown quantity at this point
wow thanks for that hmm Ideally I don't want to use cookies because the user may login on another computer etc, and so on. Thats where I was thinking of using PHP for this part ans loading some jquerie or CSS so the user can also dismiss it after, any tips?

Thanks in advance
Dave
cub is offline   Reply With Quote
Old 01-08-2012, 11:12 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
If you do not want to use Javascript cookies, then you must employ server-side scripting (PHP, ASP etc.) So ask in the PHP forum.
__________________

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 01-08-2012, 11:52 AM   PM User | #5
cub
New Coder

 
Join Date: Jan 2012
Posts: 10
Thanks: 3
Thanked 0 Times in 0 Posts
cub is an unknown quantity at this point
Okey dokey, thanks for all the help,
David
cub is offline   Reply With Quote
Reply

Bookmarks

Tags
html, javascript, php

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 12:28 PM.


Advertisement
Log in to turn off these ads.