new window

D

Den

Hi, I have one simple question:
Code:
------------
<html>
<body>
<input type="button" onclick="openWindow('http://www.google.com', 'Google')"
value="Google">
</body>
<script language="JavaScript">
function openWindow(adress,name, height, width) {
window.open(adress,name,"height="+height+", width="+width);
}
</script>
</html>
------------

This is the most simple new-window script. But I discovered something:

In IE6:
When page is uploaded on webserver, script is opening one very small window
(c. 120x160) after the click on gooogle button. That is logical, as there
is no 'height' and 'width' values. But when I run this page from my desktop,
it opens one big c. 1024x768 window (my monitor resolution is 1280x1024).

Why is that?

Firefox opens the same size window in both cases (c. 900x1000). Netscape
opens identical windows too, just smaller (c. 120x130).

Den
 
L

Lee

Den said:
Hi, I have one simple question:
Code:
------------
<html>
<body>
<input type="button" onclick="openWindow('http://www.google.com', 'Google')"
value="Google">
</body>
<script language="JavaScript">
function openWindow(adress,name, height, width) {
window.open(adress,name,"height="+height+", width="+width);

You're passing four arguments to a function that expects three,
and the syntax of the third argument is wrong (since the "height"
variable is not passed a value. It's not surprising that browsers
do unexpected things, or that they don't all do the same thing.
 
G

Guy

Den a écrit:
Hi, I have one simple question:
Code:
------------
<html>
<body>
<input type="button" onclick="openWindow('http://www.google.com', 'Google')"
value="Google">
</body>
<script language="JavaScript">
function openWindow(adress,name, height, width) {
window.open(adress,name,"height="+height+", width="+width);

window.open(adress,name,'"height='+height+', width='+width +'"');

sample :

window.open(adress,name,"toolbar=no,scrollbars=yes,resizable=yes,
height=550, width=850")

Guy
 
M

Mick White

Lee said:
Den said:


window.open(adress,name,"height="+height+",width="+width);

Mick


You're passing four arguments to a function that expects three,
and the syntax of the third argument is wrong (since the "height"
variable is not passed a value. It's not surprising that browsers
do unexpected things, or that they don't all do the same thing.
 
G

Gérard Talbot

Guy a écrit :
Den a écrit:

It should be <script type="text/javascript">

var WindowObjectReference = null;
// global variable declaration and initialisation

window.open(adress,name,"height="+height+", width="+width);
-------------------------------------------^

There should not be any blank space in the 3rd parameter (windowFeatures
string list).
window.open(adress,name,'"height='+height+', width='+width +'"');

sample :

window.open(adress,name,"toolbar=no,scrollbars=yes,resizable=yes,
height=550, width=850")

Guy

WindowObjectReference = window.open(adress, name,
"scrollbars=yes,resizable=yes,height=550,width=850");

1- no blank space in the 3rd parameter, in the windowFeatures string list
2- With height=550,width=850 values, users with a 800x600 will have the
secondary window resize automatically in Mozilla-based browsers and in
MSIE 6 SP2 due to error correction mechanism ensuring that the whole
window is rendered in the available space of the screen.
3- Storing the return value of the window.open() call is often useful.

DOM:window.open()
Best practices
http://developer.mozilla.org/en/docs/DOM:window.open#Best_practices

Gérard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top