/    Sign up×
Community /Pin to ProfileBookmark

use function once

hi!

i have a JS application which opens 4 popup windows with the same url of the parent window. (1/4 screen each)

i need the function to run once, or i will have an infinite loop….

can anyone help me, please?

mrocha

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Aug 11.2008 — What's the code you're talking about? Functions don't run multiple times unless you call them multiple times.
Copy linkTweet thisAlerts:
@mrochaauthorAug 11.2008 — i have a webpage, and i open the same web page in popup, so the function will run again in the page that opens, and again, and again.....
Copy linkTweet thisAlerts:
@xZelAug 11.2008 — Just make two copies of the same webpage but one with the popup code in it.
Copy linkTweet thisAlerts:
@mrochaauthorAug 11.2008 — i think it's not possible.

i'm creating an advertise, and i will have to introduce it in some websites, i just can't ask to all my clients to duplicate their pages.

there's no other way of doing this?

mrocha
Copy linkTweet thisAlerts:
@xZelAug 11.2008 — I actually thought about this. You could set a cookie value so before the pages are opened, and when the pages are opened, they could check the cookie to see if they should open 4 popups.
Copy linkTweet thisAlerts:
@Declan1991Aug 11.2008 — I'm not certain which is the property, but there should be a window.opener. Check if window.opener is equal to null, and if it is, run the function. Else, don't.
Copy linkTweet thisAlerts:
@toicontienAug 11.2008 — Or, create a cookie in the pop up window. If the cookie doesn't exist, run the function. When the function finishes running, create a cookie. The next time the page loads the function won't run if the cookie exists.
Copy linkTweet thisAlerts:
@HoboScriptAug 11.2008 — Or, create a cookie in the pop up window. If the cookie doesn't exist, run the function. When the function finishes running, create a cookie. The next time the page loads the function won't run if the cookie exists.[/QUOTE]

I dunno, thats not an exactly elegant way of doing it. Declans approach could be as simple as putting in:

<i>
</i>if(!window.opener) return;
Copy linkTweet thisAlerts:
@toicontienAug 11.2008 — That all depends on how the function should be run once. If it should only be run one time after the window opens, and never again until the window reopens, then Dclan's approach is best. If you want it to only open once per browsing session, or only once period (never again), then you'll need to use cookies.
×

Success!

Help @mrocha 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,
)...