Striped Fish Posted November 23, 2008 Share Posted November 23, 2008 I have a question about HTML, is it possible to write a code that randomly takes you to 1 of 4 pages? Link to comment Share on other sites More sharing options...
jeffman Posted November 24, 2008 Share Posted November 24, 2008 Yes! Using javascript or a server-side script like PHP. Here's a quick javascript example. Notice that if javascript is not enabled (not likely, but it happens), after 2 seconds, the meta-refresh still takes the user to the page of your choice. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <meta http-equiv="refresh" content="2;url=http://www.coca-cola.com"> <title></title> <script type="text/javascript"> var page_array = new Array(); // these can be extended indefinitely just by following the pattern page_array[0] = "http://www.disney.com"; page_array[1] = "http://www.coca-cola.com"; page_array[2] = "http://www.adobe.com"; page_array[3] = "http://www.google.com"; var i = Math.floor (Math.random() * page_array.length); location = page_array[i]; </script> </head> <body> <p>Please wait . . .</p> </body></html> PHP would be faster, but only if you have access to that. Link to comment Share on other sites More sharing options...
Striped Fish Posted November 24, 2008 Author Share Posted November 24, 2008 Thanks. Also is there a way to open up another page as a pop-up? Link to comment Share on other sites More sharing options...
jeffman Posted November 24, 2008 Share Posted November 24, 2008 http://www.w3schools.com/htmldom/met_win_open.asp Link to comment Share on other sites More sharing options...
Striped Fish Posted November 24, 2008 Author Share Posted November 24, 2008 Thanks, your really helpful! Link to comment Share on other sites More sharing options...
Striped Fish Posted November 24, 2008 Author Share Posted November 24, 2008 Thanks for the help I'm making a game and I needed to know that code to do that. Link to comment Share on other sites More sharing options...
cpugeek Posted November 26, 2008 Share Posted November 26, 2008 If you have access to PHP use something like this:<?php$variable_name = rand(1, 4);if ( $variable_name == 1) {Â header( 'Location: http://www.yoursite.com/page_name.html' ) ;}if ( $variable_name== 2) {Â header( 'Location: http://www.yoursite.com/page_name.html' ) ;}if ( $variable_name== 3) {Â header( 'Location: http://www.yoursite.com/page_name.html' ) ;}if ( $variable_name== 4 ) {Â header( 'Location: http://www.yoursite.com/page_name.html' ) ;}?>-make sure no html is outputted before this script--change variable_name to whatever you want to name the variable--change "http://www.yoursite.com/page_name.html" in each if statement to your page address-hope this helps. :] Link to comment Share on other sites More sharing options...
Striped Fish Posted November 26, 2008 Author Share Posted November 26, 2008 That's great, but the website I'm using to host my site doesn't allow PHP. They do allow VBScript though so I was wondering, is there a way to program the computer to use add things to fields in a database. Link to comment Share on other sites More sharing options...
cpugeek Posted November 27, 2008 Share Posted November 27, 2008 Try one of these: [i'm not sure if it's correct, but I gave it a shot, if it doesn't work tell me and give me your error code]using set urls: <%dim random_number, minimum, maximumminimum = 1maximum  = 4random_number = Int((max-min+1)*Rnd+min)if random_number = 1 thenResponse.Redirect "http://www.yoursite.com/page_name.html"end ifif random_number = 2 thenResponse.Redirect "http://www.yoursite.com/page_name.html"end ifif random_number = 3 thenResponse.Redirect "http://www.yoursite.com/page_name.html"end ifif random_number = 4 thenResponse.Redirect "http://www.yoursite.com/page_name.html"end if%> using variables: <%dim random_number, minimum, maximumdim url1, url2, url3, url4minimum = 1maximum  = 4random_number = Int((max-min+1)*Rnd+min)url1 = http://www.yoursite.com/page_name.htmlurl2 = http://www.yoursite.com/page_name.htmlurl3 = http://www.yoursite.com/page_name.htmlurl4 = http://www.yoursite.com/page_name.htmlif random_number = 1 thenResponse.Redirect (url1)end ifif random_number = 2 thenResponse.Redirect (url2)end ifif random_number = 3 thenResponse.Redirect (url3)end ifif random_number = 4 thenResponse.Redirect (url4)end if%> Link to comment Share on other sites More sharing options...
Striped Fish Posted November 27, 2008 Author Share Posted November 27, 2008 What code would I use to make a person be able to create a character, and the computer could have a password and username that would be used to log the character in? Link to comment Share on other sites More sharing options...
cpugeek Posted November 27, 2008 Share Posted November 27, 2008 Link to comment Share on other sites More sharing options...
Striped Fish Posted November 27, 2008 Author Share Posted November 27, 2008 I did that but no good replys came. Link to comment Share on other sites More sharing options...
cpugeek Posted November 27, 2008 Share Posted November 27, 2008 Try asking in the VBScript Forum they'll hopefully be able to give you some good feed back or maybe a sample script or something. :] Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.