8

I will create 5 buttons. Example:

Button1's value : 640*480
Button2's value : 1024*600
Button3's value : 1600*900
Button4's value : 800*600

If the user clicks a button, I want it to change the browser window's size. I would like to do this via JQuery but JavaScript is fine too.

EDIT:

And how can i change windows' position for computer's screen. Third question :) how can i create random number?

3
  • @Andrew i know this. But maybe JQuery haven't got function for this problem.. JQuery is a library..
    – Programmer
    Commented Oct 4, 2011 at 14:38
  • 2
    1. Please don't do this, it's really annoying to most users (unless you are setting initial size on a window that your code has opened). 2. If you must do it, in addition to resizeTo() you may want to look at moveTo(), screen.availWidth, availHeight, availLeft and availTop to centre the window once you've resized it - wrap it all up into your own custom resizeAndCentre() function. 3. Why is button 4's resolution out of sequence?
    – nnnnnn
    Commented Oct 4, 2011 at 14:47
  • 7
    Do not Edit your question to keep asking more questions! Commented Oct 4, 2011 at 14:49

2 Answers 2

18

window.resizeTo() and window.moveTo()

function changeSize( w, h){    
    window.resizeTo(w,h);
}
function movePosition( x, y){    
    window.moveTo(x,y);
}

Modern day browsers have settings that can prevent you have changing/moving/resizing the browser window.

[EDIT] Get yourself a good JavaScript reference. Math.random

1
  • 2
    Chrome doesn't allow this Commented Feb 12, 2015 at 13:34
1

In addition to epascarello's answer.

var randomnumber=Math.floor(Math.random()*11)

That's the code for a random number between 0 and 10. Change 11 to whatever you want for an increased/decreased range.

2
  • That's the code for a random number? See this site: w3schools.com/jsref/jsref_random.asp Commented Oct 4, 2011 at 14:46
  • @Andrew, I tested this code myself, use it regularly. W3Schools is somewhat accepted as a reliable source for information, so I used it. Other sites use this code as well. A quick Google search, and the first site provides the exact same info. Commented Oct 4, 2011 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.