PDA

View Full Version : browser window control function



dugfresh33
01-15-2004, 03:00 PM
I am trying to create a javascript function that will collect data from text fields in a form on the same page and assign it to variables defined in the function, which will then be used elsewhere in the function to affect the result of user actions.

Specifically, I want the user to be able to control the size of the browser window by clicking left, right, up, and down arrows. I have accomplished this already by using the following script:

function resizeMe(deltaX,deltaY) {
window.resizeBy(deltaX,deltaY);
}

and calling the script like this:

... (javascript:resizeMe('25','0'))

It works beautifully, but what I would like to do is have the user be able to enter the number of pixels themselves in a simple form, thus being able to control the size more precisely. When the user clicks the "Submit" button, I would like the values entered in the input text fields of the form to be assigned to variables in the function that would then be passed to the "deltaX" and "deltaY" params. When the user then clicks on the right, left, up, or down arrows, the window would resize by the increment defined by "deltaX" and "deltaY".

Is this too complicated? Can you just set the values of "deltaX" and "deltaY" directly from the form action?

I'm not sure how feasible this feature would be to implement on a page, whether it would enhance the browsing experience or not, but I'd still like to have the script. It just stems from all of the comments in this forum about how nobody likes having someone else take control of their browser. I thought this might be a nice compromise: the designer who wants artistic control over how the page looks can pop the page open to full screen or whatever when it's loaded, and the user who can't stand having their browser fill their screen can use this feature to control the resize. I realize that not disabling the resize handles would let them do this anyway, but this would just be another way to let the user know that you care about their experience enough to go to the trouble of creating this nice interface for them ;) It basically says you're thinking about them; that you're not too caught up in yourself and your design skills. Just another way to affect your visitors in a subconscious way...

redcircle
01-15-2004, 06:33 PM
<form>
<input type="text" name="x" /> X <input type="text" name="y" />
<input type="button" name="rsize" value="Resize Browser" onclick="resizeTo(x.value, y.value)" />
</form>


Note that you actually want to use window.resizeTo(x,y) in your function for it to work. Also note that this function is IE only and is not part of the DOM spec. With the form that I included you do not need to create the resizeMe function. resizeBy() just adds the values given to the existing browser dimensions.

dugfresh33
01-15-2004, 10:41 PM
That was very helpful and insightful. I am reminded daily why I am not a programmer. It's not so much being able to do it; it's being able to do it the right way. This, for all intents and purposes, will work just fine. It wasn't exactly what I was asking for, but as I alluded to above, what I was asking for was the equivalent of trying to get to the deli on the east side of the street...by driving west.

Again, thanks for your help. I wasn't aware that you could use the "form" tag that way. Just out of curiosity, what is the function of the / before the >?

ronniethedodger
01-15-2004, 11:26 PM
Again, thanks for your help. I wasn't aware that you could use the "form" tag that way. Just out of curiosity, what is the function of the / before the >?

You use the / on tags that do not require an end tag such as
and <hr />. The tag starts and ends with itself. Tags such as for bolding require the to tell the browser when to stop rendering bold type.

It signals to the browser that it does not need to search for the end tag, which speeds up rendering the page (I am guessing it is supposed to). Although it is not required to put the / in at all. But I think it is part of the Html specification to do so.