justuptime.com - monitor your servers & websites

Javascript Initiate Sequence

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.
Reece S's picture

He has: 169 posts

Joined: Oct 2007

I I have a Javascript code, that I want to initiate ONLY if a link is clicked.
I want to link to appear as a hyperlink, then when clicked, it will start the waiting code that will ask for the user's age, then it will cleanly redirect the parent page, without the need of popups or new windows.
If you can help, plz do so.
Thanks in advance.

mscreashuns's picture

He has: 529 posts

Joined: Jul 2005

It could go something like this:

<html>
...
<head>
&lt;script language="javascript"&gt;
function makeUpACleverName() {
...code to ask for age...
window.location = "URL HERE";
}
&lt;/script&gt;
</head>
...
<body>
<a href="#" onClick="makeUpACleverName()">Click here for the JavaScript thing</a>
</body>
</html>

'

You could also use CSS to disguise a regular tag as a link so you don't have to use a false target to have a link. Your CSS would look something like this:

.lookLikeALink {
text-decoration: underline;
cursor: pointer;
...
}

'

Reece S's picture

He has: 169 posts

Joined: Oct 2007

Ahh, this is similar to the script i made myself, i used this to verify mine, (which was wrong)
thanks for this, much appreciated.

He has: 301 posts

Joined: May 2007

What's wrong with a regular link? (I see lots wrong with inline scripting, a link that goes nowhere, etc...)

Quote: it will start the waiting code that will ask for the user's age

I wonder what kind of answer you expect? Laughing out loud

Cordially, David
--
"Old web developers don't die, they degrade gracefully..."

mscreashuns's picture

He has: 529 posts

Joined: Jul 2005

webwiz;227220 wrote: What's wrong with a regular link?

I think using a regular link is just fine, but I don't see the need for one here, so that's why I offered a little styling help. Wink

If it was redirecting to an actual new page, I would definitely suggest real links.