Welcome to WebmasterWorld Guest from 54.147.10.72

Forum Moderators: open

Message Too Old, No Replies

JS onLoad or head script

to control window size

     

Maxformed

7:09 pm on May 21, 2003 (gmt 0)

10+ Year Member



I'm redoing our website, and not sure which way to go on window sizing. I want to control the size on open/load not as a pop-up.

Currently I have images preloading on Load - can there be two onLoad handlers?

I have a script I found (not sure where) that works fairly well, except for the centering part. See here.

<script language="JavaScript" type="text/JavaScript">
//tmtC_Resize_Window
tmt_Resize_WindowX = (screen.availWidth)*.95;
tmt_Resize_WindowY = (screen.availHeight)*.95;
if (parseInt(navigator.appVersion) >= 4) window.moveTo((screen.availWidth/2)-(tmt_Resize_WindowX/2),(screen.availHeight/2)-(tmt_Resize_WindowY));
self.resizeTo(tmt_Resize_WindowX,tmt_Resize_WindowY);//tmtC_Resize_WindowEnd
</script>

Any ideas on which way to go? Should I leave out the preload images and just go with a onLoad="resizeTo(o,0);"?

Thanks

jatar_k

7:12 pm on May 21, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld Maxformed,

as to

can there be two onLoad handlers?

I use 2 on some pages like so
javascript:breakFrame();openwindow();

Maxformed

7:45 pm on May 21, 2003 (gmt 0)

10+ Year Member



Thanks. I was getting a little confused. The onLoad is in the Body of the html and I'm not sure how to add the resizeTo after the "MM_PreloadImages".

Is it possible?

jatar_k

7:49 pm on May 21, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



onLoad="javascript:MM_PreloadImages();tmtC_Resize_Window();"

I never know if you need the "javascript:" or not sometimes when i don't have it weird things happen.

tmtC_Resize_Window doesn't look to be a function though. You would need to make it a function and then put the function call into the onload in the body as above.

Maxformed

7:55 pm on May 21, 2003 (gmt 0)

10+ Year Member



That makes a lot of sense. I think that's my direction. Thanks so much, jatar_k.

tedster

8:16 pm on May 21, 2003 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I never know if you need the "javascript:" or not sometimes when i don't have it weird things happen.

The minute you've typed "onLoad=" you've already tapped into javascript - an event handler in particular. So the extra "javascript:" protocol is coming a bit late to the party, from what I know.

It would be interesting to look at an example of a misfire on this. As far as I know, the special "javascript:" protocol is only used in anchor tags, when a js function is invoked as the direct argument of the href= attribute. You shouldn't even need it in an onClick= attribute, although I often see it there.

jatar_k

8:20 pm on May 21, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



good point, tedster.

I almost never use onload but I haven't ever had the problem there. I have had the problem in onclick before but I dont have a specific site/example I can think of.

The intermittent problem with onClick has made me put it everywhere just to be paranoid.

ShawnR

3:36 am on May 22, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi All

javascript is the default client-side scripting language in most browsers, so you should be OK without the "javascript:". However, you can use other scripting languages, such as VBScript or, if you have perl installed on the client machine, perlscript.

Example:

<html>
<head><title>PerlScript sample</title>
<!-- Assumes you have Perl installed on your desktop...
........ not talking perl for cgi here; talking on your desktop, so not suitable for public Internet sites.
........ also, only works in MS IE 5.0.x or higher
-->
</head>
<body>
<form action="" Name="my_form">
<input name="ReadOut" type="Text" size="24" value="0" />
<input name="Inc" type="Button" value="add one" onclick="perlscript:$window->document->my_form->Readout->{'Value'} += 1" />
</form>
</body>
</html>

Would be great if all browsers supported it and all operating systems came with perl by default. ;)

Shawn

 

Featured Threads

Hot Threads This Week

Hot Threads This Month