help needed with Javascript

This is a discussion on "help needed with Javascript" within the JavaScript Forum section. This forum, and the thread "help needed with Javascript are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 12th, 2007, 08:28
Junior Member
Join Date: Aug 2007
Location: Australia
Age: 42
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Question help needed with Javascript

Hi

My name is Julia Andersson. I'm creating a new business website and need some help with javascript.

What I am wanting to do is have my site pop up a message when a person leaves asking them if they want to navigate away from the page or stay and join my mailing list. but I'd also like to know if it is possible to have one of those checkboxes on it allowing regular visitors to turn it off. (keeping in mind the 20/80 rule that 20% of customers provide 80% of sales... I really don't want to be annoying those ppl with the pop up... if that's what you call it)

I have used something similar on another site as a warning prior to them visiting a certain page and the script I used was
Code: Select all
<script language=javascript><!--
function checkDoD(){if (!confirm
("You are entering a restricted area of adult content. click OK if you are of legal age and want to view my delicate material. click CANCEL if you are underage or if viewing sexual content is *strictly illegal* in your country ; )"))
history.go(-1);return " "}
document.writeln(checkDoD())<!--End--></script>
I don't know how similar the script would be but that one doesn't include the facility to turn it off and that one was at the top of the new page... the one I want would have to be on the page I want it to pop up on (probably at the bottom as the last piece of code to execute) and I'm not sure what the command would be for when someone leaves (either by closing the tab/window, clicking a link in favourites or typing in a new url to visit, all of those would need to be covered.) The only one it doesn't need to pop up on is when a person clicks an internal link as the mailing list form appears on the sidebar of every page.

Could somebody please help me with this.

Thank you

Julia

Last edited by karinne; Aug 13th, 2007 at 12:24. Reason: Please use [ code ]...[ /code ] tags when displaying code. It's easier to discern code from content ;)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 12th, 2007, 10:12
Junior Member
Join Date: Aug 2007
Location: Australia
Age: 42
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help needed with Javascript

Okay, I've had a look around and attempted to create a script for this purpose (excluding the turn off function which I still need help with... if it's even possible to do it)

Here's the script
Code: Select all
<script language=javascript><!--
function displaymessage(){if (!confirm
("Wait!! Are you sure you want to navigate away from this page? Have you joined our mailing list for your chance to win a cool clip mp3 player? Click OK if you want to leave. Click CANCEL if you want to stay and join the mailing list ; )"))
history.go(-1);return " "}
document.writeln(displaymessage())<!--End--></script>
<body>
<form>
<input type="button" 
onunload="displaymessage()" 
value="Call function">
</form>
would that be about right? If it's wrong please be gentle on me LOL, remember... we were all new at this once!

Julia

Last edited by karinne; Aug 13th, 2007 at 12:24. Reason: Please use [ code ]...[ /code ] tags when displaying code. It's easier to discern code from content ;)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 12th, 2007, 10:25
Junior Member
Join Date: Aug 2007
Location: Australia
Age: 42
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help needed with Javascript

Oh, one other thing... can I throw in an exclusion to the script... for example if the visitor is simply visiting another page on my site

and don't forget the other unanswered one about whether I can allow visitors to turn the script off altogether on their computer

Thanks for the help

Julia
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Aug 12th, 2007, 14:28
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: help needed with Javascript

Your script looks ok but I have a few questions.
  1. If they click ok are you sending them back to the page they were leaving or to sign up for your mailing list?
  2. How do you want them to opt out of that one javascript? Checkbox or an "Don't display this message again" option?
IMO, prompts are not very professional and more likely to annoy users than retain them. Instead, write good solid content and include something offering them the option to sign up for for free newsletter with a chance to win a free MP3 player. Maybe an image of an MP3 player on the side of your page with text telling them they could win this by signing up for a free newsletter(with a valid email, but that's whole new bag of tricks).

Whatever you decide, we'll be happy to help.

Good Luck,
Scott
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Aug 12th, 2007, 23:33
Junior Member
Join Date: Aug 2007
Location: Australia
Age: 42
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help needed with Javascript

Quote:
Your script looks ok but I have a few questions.
  1. If they click ok are you sending them back to the page they were leaving or to sign up for your mailing list?
  2. How do you want them to opt out of that one javascript? Checkbox or an "Don't display this message again" option?
IMO, prompts are not very professional and more likely to annoy users than retain them. Instead, write good solid content and include something offering them the option to sign up for for free newsletter with a chance to win a free MP3 player. Maybe an image of an MP3 player on the side of your page with text telling them they could win this by signing up for a free newsletter(with a valid email, but that's whole new bag of tricks).

Whatever you decide, we'll be happy to help.

Good Luck,
Scott
Thanks for the feedback Scott.

In answer to your questions, the mailing list form is on the page that they would be leaving (actually it will be on every page within my site.. because it's in the sidebar, hence not needing the script to run if they're visiting an internal link)

And I was thinking along the lines of a "Don't display this message again" option.

If you want to have a look at the site visit http://www.free-electronics-source.com I'm not sure that it will come up for you yet though because the filename isn't 'index.html' or anything like that (it comes up on my computer but for some reason not on my daughters when I type in the url). The sidebar contains a picture of the mp3 and the blurb about joining the free mailng list to receive regular updates and a chance to win it.

In any case, the point may be moot since I attempted to install that script but it didn't work. I may need to change the format of my page. My ecommerce coach suggested the blog format but I'm finding it somewhat limiting. Even if I decide not to use the javascript, my current format has nowhere to include meta tags and meta keywords for the benefit of SEO. While there are conflicting reports as to the effectiveness of such tags in increasing SE rankings I still want to include them... just in case.

Thanks again

Julia

Oh, just to clarify... the blog format I'm using is WordPress

Last edited by JewelEnterprises; Aug 12th, 2007 at 23:41. Reason: adding clarification about WordPress
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 13th, 2007, 02:30
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: help needed with Javascript

Ok, heres my opinion (for what it's worth). I like the idea of having the image in the sidebar with the option for signing up for the newsletter. Since you want to use javascript for your prompt, I would use cookies.
  1. Set a cookie
  2. The first time they leave show the prompt and save that data in the cookie (that the prompt has been shown already)
  3. Each time they leave, do a check to see if they have seen your prompt. If they have, do not show it again.
Also, if they click cancel I would direct them to the portion of your page with newsletter info with an id.

Good Luck,
Scott
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Aug 13th, 2007, 02:46
Junior Member
Join Date: Aug 2007
Location: Australia
Age: 42
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help needed with Javascript

Quote:
Originally Posted by ScottR View Post
Ok, heres my opinion (for what it's worth). I like the idea of having the image in the sidebar with the option for signing up for the newsletter. Since you want to use javascript for your prompt, I would use cookies.
  1. Set a cookie
  2. The first time they leave show the prompt and save that data in the cookie (that the prompt has been shown already)
  3. Each time they leave, do a check to see if they have seen your prompt. If they have, do not show it again.
Also, if they click cancel I would direct them to the portion of your page with newsletter info with an id.

Good Luck,
Scott
Thanks again Scott... I like that idea. Now the question is, how do I do that?

Sincerely

Julia
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Aug 13th, 2007, 04:02
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: help needed with Javascript

OK, I'll give you the code for setting a cookie to get you started.
Code: Select all
if (!document.cookie) {
document.cookie = "newsletter=" + 0 + 
"; max-age=" + (60*60*24*365);
}
That sets a cookie with a name of newsletter with a value of 0. And max-age gives it a lifetime of one year. Then if your user has seen your prompt, rewrite the cookie name to have a value of one. Now, when the user exits the page check the value of the cookie name, and only display the prompt if the value is 0.

I didn't test this, just threw it together.
Good Luck,
Scott
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Aug 13th, 2007, 05:56
Junior Member
Join Date: Aug 2007
Location: Australia
Age: 42
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help needed with Javascript

Quote:
Originally Posted by ScottR View Post
OK, I'll give you the code for setting a cookie to get you started.
Code: Select all
if (!document.cookie) {
document.cookie = "newsletter=" + 0 + 
"; max-age=" + (60*60*24*365);
}
That sets a cookie with a name of newsletter with a value of 0. And max-age gives it a lifetime of one year. Then if your user has seen your prompt, rewrite the cookie name to have a value of one. Now, when the user exits the page check the value of the cookie name, and only display the prompt if the value is 0.

I didn't test this, just threw it together.
Good Luck,
Scott
Thank you Scott

So using that I would not need to worry about having a "do not show this prompt again" option... it would happen automatically?

Julia
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Aug 13th, 2007, 12:33
Junior Member
Join Date: Aug 2007
Location: Australia
Age: 42
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help needed with Javascript

Okay, something has gone skewiff... I added this script to my index.php file

Code: Select all
 
<script language=javascript><!--
function displaymessage(){if (!confirm
("my message; )"))
history.go(-1);return " "}
document.writeln(displaymessage())<!--End--></script>
<form>
<input type="button" 
onunload="displaymessage()" 
value="Call function">
</form>
And instead of it popping up on the unload, it popped up when the page loaded

So I removed it again.

I tried adding it to my sidebar in a text file with the same result. The prompt came up when my page loaded unstead of when it unloaded.

So I removed it again!!

What am I doing wrong? Is it the script or something else.

HELP ME PLEEEEEEEAAAAAAAAAASSSSSSSEEE LOL

Julia

Last edited by JewelEnterprises; Aug 13th, 2007 at 12:59. Reason: another post edited for not using the code tags
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Aug 13th, 2007, 12:36
Junior Member
Join Date: Aug 2007
Location: Australia
Age: 42
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: help needed with Javascript

Dang I hate website development sometimes LOL

Heheh, but what is life without a little challenge?

Julia
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Aug 13th, 2007, 15:32
Reputable Member
Join Date: Dec 2005
Location: U.S.A.
Posts: 155
Thanks: 0
Thanked 4 Times in 4 Posts
Re: help needed with Javascript

Ha Ha, isn't programming fun? I would take that function and put it in an onUnload handler in your body tag. Also I see no need to use writeIn for your prompt. Just put it right in the prompt.

As for your other question. All you need to do is a loop (if your familiar with loops) and check the value of the cookie. If the value is 1 do not show the message, otherwise show the message. If the value is 0, make sure you change the value of the cookie to 1.
__________________
Web Design and Development
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
help, javascript

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Javascript menu needed! themightymac JavaScript Forum 1 Jan 26th, 2008 14:53
Designers needed, cloners needed. TargeTemplate Job Opportunities 0 Dec 27th, 2007 03:41
what does + + mean in Javascript eg: var m = (A1+ +B4); Andy K JavaScript Forum 6 Dec 13th, 2006 23:57
Can someone help me with this javascript Galaxyblue JavaScript Forum 2 Mar 11th, 2004 12:18
Javascript mikegu JavaScript Forum 1 Oct 16th, 2003 08:19


All times are GMT. The time now is 21:14.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved