/    Sign up×
Community /Pin to ProfileBookmark

Code for One-Time Pop Up

If anyone has the time and inclination, would they please modify this code so that the pop-up it calls only pops up once per user visit? Much obliged!

[B]This is the part of the script that goes in the HEAD —[/B]

<SCRIPT language=”JavaScript”>
function PopupMe(){
setTimeout(‘__PopupMe()’,1000);}
function __
PopupMe(){
myleft=(screen.width)?(screen.width+500)/2:1;mytop=(screen.height)?(screen.height-200)/2:50;
settings=’top=’ + mytop + ‘,left=’ + myleft + ‘,width=250,height=150,location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=yes,fullscreen=no’
PopupWin=window.open(‘http://ampheek.com/popped.htm’,’PopupWin‘, settings);
PopupWin.focus();
setTimeout(‘PopupWin.close()’,7000);}
</SCRIPT>

[B]This is the part of the script that goes in the BODY[/B]

<BODY onload=”javascript?opupMe()”BGCOLOR=”#ffffff”>

Thanks again folks ?

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JMay 26.2005 — Here is an example using a session cookie where the popup will be shown on the first visit to the page, it is not shown again until the visitor closes and reopens their browser.

To extend this to a longer period you would have to use a persistant cookie

[code=php]<HTML>
<HEAD>
<TITLE>Document Title</TITLE>

<script type="text/javascript">
<!--
var cookie_value = 0

function get_cookie(name){
var cookie_name = name + "="

if (document.cookie.length > 0){
start_index = document.cookie.indexOf(cookie_name)

if (start_index != -1) {
start_index += cookie_name.length

end_index = document.cookie.indexOf(";", start_index)

if (end_index == -1){
end_index = document.cookie.length
}

cookie_value=unescape(document.cookie.substring(start_index, end_index))

}

}

if(cookie_value == 0){
document.cookie="pop_once = 1"
PopupMe()
}

}

function PopupMe(){
setTimeout('__PopupMe()',1000)
}

function __PopupMe(){
myleft=(screen.width)?(screen.width+500)/2:1;mytop=(screen.height)?(screen.height-200)/2:50;
settings='top=' + mytop + ',left=' + myleft +',width=250,height=150,location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=yes,fullscreen=no'
PopupWin=window.open('http://ampheek.com/popped.htm','PopupWin', settings);
PopupWin.focus();
setTimeout('PopupWin.close()',7000);}

//-->
</script>
</HEAD>
<BODY onload="get_cookie('pop_once')">

</BODY>
</HTML>[/code]
Copy linkTweet thisAlerts:
@porquatauthorMay 27.2005 — MrJ ---

Egads!! Shazam!! Sufferin' succotash!! Your code works. I really appreciate your help, and after visiting your website am further astounded. The Hunting Ground is incredible.
Copy linkTweet thisAlerts:
@Mr_JMay 27.2005 — I certainly appreciate your re-coding of my one-time pop up gadget. It works beautifully, except the user still gets the pop up twice, not just once. That's no problem though. After that they'll not see it again.[/QUOTE]

I am puzzled as to why it shows twice for you, I copied and pasted from my previous post just to make sure that this forum had not messed the code up in some way.

I only got the popup once when I opened the page for the first time.

Every time I refreshed the page after that the popup remained closed.

Only when I closed and re-opened the browser did the popup open again, which is how a session cookie works.

Hmm .....strange .................
Copy linkTweet thisAlerts:
@porquatauthorMay 27.2005 — MrJ --

I suspect the minor glitch in the code resulted from the GUI website editor I use. It's antiquated and known to cause hiccups now and again. I'll copy and paste using plain old Notepad and see what happens.
Copy linkTweet thisAlerts:
@denverwholesaleFeb 18.2015 — Mr J, could you do the same for me please?

Here is the code in the head:

</script>

<div id='2016-denver-wholesale-amber'></div>

<script type="text/javascript"> (function() { var hm = document.createElement('script'); hm.type ='text/javascript'; hm.async = true; hm.src = ('++u-heatmap-it+log-js').replace(/[+]/g,'/').replace(/-/g,'.'); var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(hm, s); })(); </script>
Copy linkTweet thisAlerts:
@Agen_bolaFeb 19.2015 — Good code for me..

Good job..

regards,
×

Success!

Help @porquat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...