/    Sign up×
Community /Pin to ProfileBookmark

Making script prompt two different events

Making script prompt two different events

On the web page’s load, I want the browser to automatically prompt the user to bookmark a specified page.

I know these can only be done in Internet Explorer.

I have developed the following script, which works five:

[COLOR=darkred]<head>[/COLOR]
[COLOR=blue]<script type=”text/javascript”>[/COLOR]
function addbookmark(){
if (document.all)
window.external.AddFavorite(“http://www.SiteA.com”,”Site A”)
}
[COLOR=blue]</script>[/COLOR]
[COLOR=darkred]</head>[/COLOR]
[COLOR=green]<body onLoad=”addbookmark()”>[/COLOR]

[COLOR=green]</body>[/COLOR]

What I need help is, I would like the script to prompt one of two different sites, such as Site A and Site B.

Half of the users when going to my site will be automatically be prompted to bookmark Site A, but the other half will automatically be prompted to bookmark Site B.

I don’t know what to do, and any help on this would greatly be appreciated.

Thanks in advanced! :p

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@javaNoobieSep 02.2004 — You can use Math.random() to generate random values. And base on these values, prompt the appropriate site.
Copy linkTweet thisAlerts:
@shopkanjiauthorSep 02.2004 — I thought about that but I’m not good enough at scripting to learn how to implement this.

I was thinking of creating a variable number based on a math random number function, then having something where if the number is between 0 and 0.500000 then this prompt happens, and if it is between 0.500001 and 1 then the second prompt happens.

I just don’t know how to actually to write this in JavaScript.
Copy linkTweet thisAlerts:
@javaNoobieSep 02.2004 — Here's the code. Hope this helps
&lt;script type="text/javascript"&gt;
window.onload = new function(){
var temp = parseInt(Math.random() * 2); //generate values between 0 and 1
if(temp == 0){
alert('Site A');
}else{
alert('site B');
}

<i> </i>}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@shopkanjiauthorSep 02.2004 — This works great!!!!!!

Thank you very much!
×

Success!

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