ThomL Posted March 12, 2018 Posted March 12, 2018 or you can just update the variable that holds the urls....... var items = Array('http://www.google.com','http://www.youtube.com','http://www.bing.com','http://www.bbc.co.uk','http://www.edugeek.net');
Knil92 Posted March 12, 2018 Author Posted March 12, 2018 also adding http:// to the urls in the array works and sends people to the correct url
Knil92 Posted March 12, 2018 Author Posted March 12, 2018 (edited) or you can just update the variable that holds the urls....... var items = Array('http://www.google.com','http://www.youtube.com','http://www.bing.com','http://www.bbc.co.uk','http://www.edugeek.net'); aha i literally just tried that lol Edited March 12, 2018 by Knil92
Knil92 Posted March 12, 2018 Author Posted March 12, 2018 [color=#0000FF]<[/color][color=#800000]html[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]body[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]p[/color][color=#0000FF]>[/color]This redirects a random URL from a variable with Javascript:[color=#0000FF][/color][color=#800000]p[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]button [/color][color=#FF0000]type[/color][color=#0000FF]="button"[/color][color=#FF0000] onclick[/color][color=#0000FF]="getURL()"[/color][color=#0000FF]>[/color]>Click Me![color=#0000FF][/color][color=#800000]button[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]p [/color][color=#FF0000]id[/color][color=#0000FF]="demo"[/color][color=#0000FF]>[/color][color=#800000]p[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]p[/color][color=#0000FF]>[/color]This does the same as the button except it uses an image:[color=#0000FF][/color][color=#800000]p[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]input [/color][color=#FF0000]type[/color][color=#0000FF]="image"[/color][color=#FF0000] src[/color][color=#0000FF]="https://images-na.ssl-images-amazon.com/images/I/51a8L-dlWzL._UX385_.jpg"[/color][color=#FF0000] onclick[/color][color=#0000FF]="getURL()"[/color][color=#0000FF]>[/color][color=#800000]button[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]p [/color][color=#FF0000]id[/color][color=#0000FF]="demo"[/color][color=#0000FF]>[/color][color=#800000]p[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]script[/color][color=#0000FF]>[/color] [color=#0000FF]function[/color] getURL() { [color=#0000FF]var[/color] items = Array([color=#800000]'http://www.google.com'[/color],[color=#800000]'http://www.youtube.com'[/color],[color=#800000]'http://www.bing.com'[/color],[color=#800000]'http://www.bbc.co.uk'[/color],[color=#800000]'http://www.edugeek.net'[/color]); [color=#0000FF]var[/color] item = items[Math.floor(Math.random()*items.length)]; [color=#0000FF]var[/color] win = window.open(item, [color=#800000]'_blank'[/color]); win.focus(); } [color=#0000FF][/color][color=#800000]script[/color][color=#0000FF]>[/color] [color=#0000FF][/color][color=#800000]body[/color][color=#0000FF]>[/color] [color=#0000FF][/color][color=#800000]html[/color][color=#0000FF]>[/color] I've added a little bit extra to it instead of using a button I figured out how to use an image
Garacesh Posted March 12, 2018 Posted March 12, 2018 Rather than using an image you could use a button and then just use CSS to style the button
ThomL Posted March 12, 2018 Posted March 12, 2018 Style the button with an SVG and be all fancy and modern
Garacesh Posted March 12, 2018 Posted March 12, 2018 Style the button with an SVG and be all fancy and modern Can you do onClick with an SVG? I thought that was inherent to buttons?
Garacesh Posted March 12, 2018 Posted March 12, 2018 (edited) Rather than using an image you could use a button and then just use CSS to style the button You can use CSS (Cascading Style Sheets) to change the default display properties of basically any element. For example, rather than putting ../img/Header.png at the top of every web page, you could simply do and define the header element in your stylesheet #header { width: 768px; height: 250px; margin-top: 20px; margin-left: auto; margin-right: auto; margin-bottom: 20px; background-image: url("../img/Header.png"); } An image header isn't the best example though.. You can go much further, dictating default font colour, size, style, element background colours/gradients, image effects, so much stuff. If you do even basic web design, it can be incredibly useful. Edited March 12, 2018 by Garacesh 1
Knil92 Posted March 12, 2018 Author Posted March 12, 2018 yeah I've heard about css and the concept behind them, it was more of the SVG, I'M NOT A FARMER DAMMIT XD
Garacesh Posted March 13, 2018 Posted March 13, 2018 Scalable Vector Graphics, you can code an image (so to speak) by listing its properties and it'll be created as a vector so it'll scale up and down without becoming distorted or pixellated. It's a really good idea in concept but I don't think I've ever actually used it. 1
Knil92 Posted March 13, 2018 Author Posted March 13, 2018 Thats interesting, I'd rather just use a vector graphic that is saved at different sizes XD Also I've been playing around with that stuff you guys did yesterday and I've been trying to set it up so the button goes to a redirect page and then the script runs once that page has loaded I've got this so far but adblock blocks it, how would I make it to just load in the current window rather than it create a new tab? [color=#0000FF]<[/color][color=#800000]head[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]body [/color][color=#FF0000]onload[/color][color=#0000FF]="getURL();"[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]script[/color][color=#0000FF]>[/color] [color=#0000FF]function[/color] getURL() { [color=#0000FF]var[/color] items = Array([color=#800000]'http://www.bing.com/'[/color],[color=#800000]'http://www.edugeek.net/'[/color],[color=#800000]'http://www.msn.com'[/color]); [color=#0000FF]var[/color] item = items[Math.floor(Math.random()*items.length)]; [color=#0000FF]var[/color] win = window.open(item, [color=#800000]'_blank'[/color]); win.focus(); document.getElementById([color=#800000]"MyFrame"[/color]).src=item; }[color=#0000FF][/color][color=#800000]script[/color][color=#0000FF]>[/color][color=#0000FF][/color][color=#800000]body[/color][color=#0000FF]>[/color][color=#0000FF][/color][color=#800000]Head[/color][color=#0000FF]>[/color]
Katy Posted March 13, 2018 Posted March 13, 2018 Thats interesting, I'd rather just use a vector graphic that is saved at different sizes XD Also I've been playing around with that stuff you guys did yesterday and I've been trying to set it up so the button goes to a redirect page and then the script runs once that page has loaded I've got this so far but adblock blocks it, how would I make it to just load in the current window rather than it create a new tab? [color=#0000FF]<[/color][color=#800000]head[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]body [/color][color=#FF0000]onload[/color][color=#0000FF]="getURL();"[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]script[/color][color=#0000FF]>[/color] [color=#0000FF]function[/color] getURL() { [color=#0000FF]var[/color] items = Array([color=#800000]'http://www.bing.com/'[/color],[color=#800000]'http://www.edugeek.net/'[/color],[color=#800000]'http://www.msn.com'[/color]); [color=#0000FF]var[/color] item = items[Math.floor(Math.random()*items.length)]; [color=#0000FF]var[/color] win = window.open(item, [color=#800000]'_blank'[/color]); win.focus(); document.getElementById([color=#800000]"MyFrame"[/color]).src=item; }[color=#0000FF][/color][color=#800000]script[/color][color=#0000FF]>[/color][color=#0000FF][/color][color=#800000]body[/color][color=#0000FF]>[/color][color=#0000FF][/color][color=#800000]Head[/color][color=#0000FF]>[/color] This should open in current tab: [color=#0000FF]<[/color][color=#800000]head[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]body [/color][color=#FF0000]onload[/color][color=#0000FF]="getURL();"[/color][color=#0000FF]>[/color] [color=#0000FF]<[/color][color=#800000]script[/color][color=#0000FF]>[/color] [color=#0000FF]function[/color] getURL() { [color=#0000FF]var[/color] items = Array([color=#800000]'http://www.bing.com/'[/color],[color=#800000]'http://www.edugeek.net/'[/color],[color=#800000]'http://www.msn.com'[/color]); [color=#0000FF]var[/color] item = items[Math.floor(Math.random()*items.length)]; [color=#0000ff]location.href [/color]= item; }[color=#0000FF][/color][color=#800000]script[/color][color=#0000FF]>[/color][color=#0000FF][/color][color=#800000]body[/color][color=#0000FF]>[/color][color=#0000FF][/color][color=#800000]Head[/color][color=#0000FF]>[/color] 2
Garacesh Posted March 13, 2018 Posted March 13, 2018 Well isn't the entire point of a vector that it can be resized to any resolution and not lose detail? Anyway. The script. You might want to try using window.location.href instead of window.open. Edit: Katy wins again. 1
ThomL Posted March 13, 2018 Posted March 13, 2018 Seems like you're getting this script nice and buttoned up!
Knil92 Posted March 19, 2018 Author Posted March 19, 2018 So here's what I put together, its not fancy but its something XD Mysterin If you have any weird or wonderful websites that not many people know about that I can add to the list of websites, let me know (Y) 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now