...

View Full Version : how to set the dimensions and coordinate of a window



davidklonski
07-14-2004, 11:31 AM
Hello

I would like to force the initial location of a window to the (0,0) coordinate and give it a specific width and height when it loads.

I use the following:


function initPage() {
window.moveTo(0, 0);
window.resizeTo(400, 400);
}

I call this function at the onload event of the page body.
I get an error saying: "Access is denied"

what is the problem with the code? what could be causing this?
thanks

glenngv
07-14-2004, 11:40 AM
What browser are you using? Some browsers such as Firefox allows the user to control the usage of javascript to move or resize existing windows.

davidklonski
07-14-2004, 11:44 AM
I am using IE6

jamescover
07-14-2004, 12:02 PM
<script>
<!--

function initPage() {
window.moveTo(0,0);
window.resizeTo(400,400);
}
window.onload=initPage;

//-->
</script>

You are putting this script in the parent window? It works, as expected, in IE 5.0, as well as, NN4.06, although, in NN you will get a window viewing area of 400x400, whereas in IE the window width/height is 400x400.


-james

glenngv
07-14-2004, 12:20 PM
Maybe the error is in the other codes. Could you post a link or attach the related codes?

Kor
07-14-2004, 12:27 PM
Same ok with the code for me either. Works with IE6, Moz Firefox, Moz 1.7, NS6, NS7 on XP, Home edition

It does not work on Opera 7.5 but no error is displayed on it's console

davidklonski
07-14-2004, 12:38 PM
when I changed the line from


<body onload="initPage();">

to


window.onload=initPage;

It started working...
thanks

davidklonski
07-14-2004, 12:48 PM
I think I know what the problem is (yes, the problem still exists).
My page contains several IFrames.
Maybe there is a problem in moving or resizing the page if one of the iframes didn't finish loading yet...
Is this relevant?
What doe the "Access denied" error mean?

How can I solve it?
When using regular frames, I know that I can count on the onload attribute of the frameset. Is there a similar solution for iframes?

glenngv
07-14-2004, 01:04 PM
"Access denied" usually means you're accessing a window/frame/iframe that contains a page in different domain.

jamescover
07-14-2004, 01:25 PM
"Access denied" usually means you're accessing a window/frame/iframe that contains a page in different domain


That's all I can think of...do you have someone else's domain loaded into the iframe/window?





-james

davidklonski
07-14-2004, 01:46 PM
no I don't
The site I am working on is still in development and all the files I am using are local on my machine.

Willy Duitt
07-14-2004, 01:57 PM
I thought this question was answered hours ago over here (http://www.webdeveloper.com/forum/showthread.php?threadid=39495).....

jamescover
07-14-2004, 02:01 PM
I thought this question was answered hours ago over here.....


ha ha...


I get an error saying: "Access is denied"

I don't know, that's the only circumstance under which I've seen that error...



-james

davidklonski
07-14-2004, 09:27 PM
Here is a simpel html code that reproduces the same bug.
I would appreciate if someone could point me to the silly error that I am missing:


<html>
<head>
<script type="text/javascript">
<!--
function initPage() {
window.moveTo(0, 0);
window.resizeTo(400, 300);
}
// -->
</script>
</head>
<body onload="initPage()">
test
</body>
</html>


I am getting Access denied error on this page when I go to it via Apache. When I go there directly via the browser's "open page" menu, then it works fine.

glenngv
07-15-2004, 04:03 AM
Works fine for me in IE6 (with SP1;Q832894 patches) and even in Firefox. Must be your IE.

Kor
07-15-2004, 09:02 AM
Same for me, works ok either with the handler inside the code or in body tag (in fact that is normal, as there is no difference between those 2 ways) on all browsers I have, IE, Moz or Gecko

Thus, I guess Glenn is right, reinstall your browser, something is wrong with it.

davidklonski
07-15-2004, 09:49 AM
are you testing it via Apache?
because it works OK for me when I open the page in the browser not via apache.

but via apache I am getting the error.
I have set my browsing to 'display notification on every script error'

glenngv
07-15-2004, 02:06 PM
It works for me in IIS. But it has nothing to do with the server. It's a client-side issue. It's weird that it doesn't work for you when the page is accessed online on an apache server. Is your server accessible on the internet? Maybe if you post a link we could test it ourselves directly.

MichaelBowler
07-15-2004, 08:19 PM
When you use open from the file menu a popup appears now that popup will resize to the size defined within the javascript on the page it loads if there is no javascript specifying the size it will popup the same size as the last window which maximized but if you use the address bar then the size of the window is already defined and that is where I reckon the error is coming from there just a theory tho :)

SpiritualStorms
07-15-2004, 09:23 PM
Are the coordinates for a mini window, like a pop up?

M1k3-+i3
07-29-2004, 10:45 PM
I reckon the coordinates for popups and mini windows would be the same. As far as know they use x & y like so (00, 00) :)

I was a little slow to reply.

SpiritualStorms
07-30-2004, 01:07 AM
I thought so. That's why i sort of found this thread a bit odd. Here's what was posted in the opening thread:


function initPage() {
window.moveTo(0, 0);
window.resizeTo(400, 400);
}


Anyway, i found it odd that the top, and left properties werent used to control where exactly on the screen the mini window would appear. I always thought the moveTo(), and resizeTo() methods were only effective if you were using like a piece of script.

0xG
07-30-2008, 06:53 PM
I struggled with this for some time, too.
Here is the solution:

This is due to a race condition; the window has not actually finished loading, and so is not ready to accept a resize command. Sure, it "works" for some people, probably because they already have their browser window open - rather than clicking the HTML (or HTA) file to cause the browser to launch.
I used a delay to launch the ResizeTo:

Window.SetTimeout "Window.ResizeTo 800, 600", 1000 ' (vbscript)
Window.SetTimeout ( "Window.ResizeTo ( 800, 600)", 1000) /* other */

The above uses a 1 second (1000 ms) delay; this may be tuneable but you don't always know how slow the users PC is; mine is quite fast.

PS I am not sure of the exact syntax in the second example, but you get the idea. This totally solves the issue.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum