1

I have a custom function that will open a window to the center of the screen from a different url. On my current case I am opening a url outside my domain. This is my function.

function wopen(url, name, w, h) {
    w += 32;
    h += 96;
    wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;
    if (wleft < 0) {
        w = screen.width;
        wleft = 0;
    }
    if (wtop < 0) {
        h = screen.height;
        wtop = 0;
    }
    var win = window.open(url,
                name,
                'width=' + w + ', height=' + h + ', ' +
                'left=' + wleft + ', top=' + wtop + ', ' +
                'location=no, menubar=no, scrollbars=yes');
    // +
    //'status=no, toolbar=no, scrollbars=no, resizable=yes');
    win.resizeTo(w, h);
    win.moveTo(wleft, wtop);
    win.focus();
}

This works perfectly on IE6, and FF but not on IE7

Kara
  • 6,115
  • 16
  • 50
  • 57
Aivan Monceller
  • 4,636
  • 10
  • 42
  • 69
  • I would guess this is a security issue of IE7 preventing scripting through cross-domains or check that it isn't blocked as a popup. – Martin Buberl Feb 06 '11 at 16:44
  • @Martin - the popup opens as expected but I recieve the IE javascript debugger error on the line `win.resizeTo(w,h);` – Aivan Monceller Feb 06 '11 at 17:13
  • Have you checked this answer (maybe that helps you): http://stackoverflow.com/questions/60030/how-do-you-resize-an-ie-browser-window-to-1024-x-768/60209#60209 – Martin Buberl Feb 06 '11 at 17:19

2 Answers2

1

there are many security things that a browser and os checks for any window.

for this case, i am not sure but try this also. if your mouse button is clicked and hold on at the time of resizing browser window through your js code then you will get access denied error.

reason is OS denied such activities when real physical users is ready for mouse drag event.

see below url http://prcoldfusion.blogspot.com/2012/06/access-denied-javascript-error-internet.html

prashant
  • 11
  • 1
1

The issue is that you are attempting to open a window with a separate domain, which in IE7 and higher is considered a security issue. Essentially, when you open that new window, it creates a new process and leaves your process separate, so you can no longer manipulate that other window.

http://social.msdn.microsoft.com/Forums/en/iewebdevelopment/thread/e9cebb92-f943-4a79-b29b-7376039ea6a0

http://msdn.microsoft.com/en-us/library/Bb250462.aspx

So, once you open that new window with a domain different from your own, you lose control of it. I don't see a way to change this without adjusting the end-users computer.

EDIT

Hmm, apparently you can get around this by opening a window that you do have control of, then changing the window.location.href to your url. Try this:

function wopen(url, name, w, h) {
    w += 32;
    h += 96;
    wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;
    if (wleft < 0) {
        w = screen.width;
        wleft = 0;
    }
    if (wtop < 0) {
        h = screen.height;
        wtop = 0;
    }
    var win = window.open('about:blank', // <- Note about:blank
                name,
                'width=' + w + ', height=' + h + ', ' +
                'left=' + wleft + ', top=' + wtop + ', ' +
                'location=no, menubar=no, scrollbars=yes');
    // +
    //'status=no, toolbar=no, scrollbars=no, resizable=yes');
    win.location.href = url;
    win.resizeTo(800, 150);
    win.moveTo(wleft, wtop);
    win.focus();
}
wopen('http://www.yahoo.com/', 'yahoo', 250, 250);

I don't know if this is a hack or not; I'm surprised it's that easy to get around, at least for changing window resize and whatnot. But, it works (at least on IE8).

Jared Farrish
  • 48,585
  • 17
  • 95
  • 104
  • No problem. :) I really was surprised it was so easy to get around IE's security architecture in this case, although I'm not sure if this is or isn't a security issue they may plug in the future. – Jared Farrish Feb 06 '11 at 22:15