Sunday, April 3, 2011

"Access is Denied" error in javascript

I am using window.open(0 method to open a new popup window. It's showing javascript error "Access Denied". My code is below:

Script Code:

function wopen(url, name, w, h)
{
    var win = window.open(url,
                  name, 
                  'width=' + w + ', height=' + h + ', ' +
                  'location=no, menubar=no, ' +
                  'status=no, toolbar=no, scrollbars=no, resizable=no');
    win.resizeTo(w, h); 
    win.focus();       
}

HTML Code:

<a href="<%=link("*","PopupDisplay")%>" target="popup" 
    onClick="wopen('<%=link("*","PopupDisplay")%>', 'popup', 450,200); return false;" 
    id ="CommerceQuery_fourpartlink"4 Part Key#</a>

// "PopupDisplay" will forward to the corresponding link
From stackoverflow
    1. See if you have any popup blockers enabled.
    2. A security restriction on window.open is that you can only open windows in the same domain, to prevent any cross domain security forgeries. see http://www.mozilla.org/projects/security/components/ConfigPolicy.html
    3. make sure that your current script can access the window object. Some scripts in iframes, etc cannot open window objects.
    Cerebrus : +1 for mentioning the same/different domain issue. That was what I had in mind.

0 comments:

Post a Comment