Html Random
- Boltrig
-
Boltrig
- Member since: Mar. 17, 2006
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
Im looking to implement a random function in HTML. if a user clicks a link, it will take them to one of 2 pages. Does anyone know how to implement this?
Thanks in advance all.
- ApatheticMark
-
ApatheticMark
- Member since: Apr. 29, 2005
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
woop.
- ApatheticMark
-
ApatheticMark
- Member since: Apr. 29, 2005
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
Sorry,
<a href="#" onclick="javascript:i=Math.round(Math.random(
));if(i){window.location='http://www.google.c om';}else{window.location='http://www.newgrou nds.com';}" title="Random Page!">Linkage</a>
if that doesn't work (replace [ and ] with <a nd >),
[a href="#" onclick="javascript:i=Math.round(Math.random(
));if(i){window.location='http://www.google.c om';}else{window.location='http://www.newgrou nds.com';}" title="Random Page!"]Linkage[/a]
All one line, remember
woop.
- Boltrig
-
Boltrig
- Member since: Mar. 17, 2006
- Offline.
-
- Forum Stats
- Member
- Level 17
- Blank Slate
Thanks man. Ill give it a go. Is that still compatable with a site defined as html/css
ie can i define javascript as well
- smulse
-
smulse
- Member since: Mar. 24, 2005
- Offline.
-
- Forum Stats
- Member
- Level 31
- Blank Slate
At 3/14/07 05:36 PM, Boltrig wrote: Thanks man. Ill give it a go. Is that still compatable with a site defined as html/css
ie can i define javascript as well
It won't interfere with any of your HTML/CSS.
- elbekko
-
elbekko
- Member since: Jul. 23, 2004
- Offline.
-
- Forum Stats
- Member
- Level 16
- Blank Slate
In an onclick, there's no need to put 'javascript:'. It's always javascript.
"My software never has bugs. It just develops random features. " - Unknown
[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]
- DFox
-
DFox
- Member since: Aug. 9, 2003
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
At 3/14/07 06:18 PM, elbekko wrote: In an onclick, there's no need to put 'javascript:'. It's always javascript.
Dunno, I always target JavaScript and it seems a lot of people do too.
- henke37
-
henke37
- Member since: Sep. 10, 2004
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
I recommend against solely javascript in this case, what about the users who does not have javascript?
Or why even have a random link to start with?
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.
- DFox
-
DFox
- Member since: Aug. 9, 2003
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
At 3/15/07 07:31 AM, henke37 wrote: I recommend against solely javascript in this case, what about the users who does not have javascript?
If you find yourself catering to the 1% or whatever visitors who don't have JavaScript enabled, then you have bigger problems than that.
- henke37
-
henke37
- Member since: Sep. 10, 2004
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
Actually it is about 10 %, quite an amount. And in most cases, you do not need to remove the javascript, just provide alternative methods. For example the simple task of creating a popup link. There are all sorts of issues, the user might not support multiple windows properly(Wii opera), it might have a hyper reactive popup blocker or may have disabled javascript in the browser to not get nailed by the next javascript vulnerability. But all these cases can be solved by simply placing the real address in the href attribute and placing the popup code in an event handler.
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.
- DFox
-
DFox
- Member since: Aug. 9, 2003
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
At 3/15/07 12:04 PM, henke37 wrote: For example the simple task of creating a popup link.
That's wonderful but that isn't the point being made here.
He asked how to make the link random which requires a server side language OR JavaScript. There's no alternative like a simple HTML link to popup windows for this...
Obviously you should try to avoid using JavaScript popups, but for a task like this JavaScript is the way to go if you don't have access to a server-side language.
Also, 94% of clients have JavaScript enabled and that number is only going up. If someone doesn't have JavaScript enabled, their web browsing experience is going to be god awful anyway.


