Jump to content

Recommended Posts

Posted

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');

Posted (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 by Knil92
Posted


[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 :D instead of using a button I figured out how to use an image

Posted (edited)
Rather than using an image you could use a button and then just use CSS to style the button :p

 

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 by Garacesh
  • Thanks 1
Posted

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.

  • Thanks 1
Posted

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]

Posted
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]

  • Thanks 2
Posted

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.

  • Thanks 1
Posted
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)
  • Thanks 1

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...