Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 306
  • Last Modified:

Window.open() is not working even if i disable pop blocker

Experts,

Is there any reason why this code should not work or be blocked by the pop blocker? Even if i have disabled that thing.
function openReportWindow(strURL) 
{
    try
    {
    
        var top = (window.screen.height - 580) / 2;
        var left = (window.screen.width - 1000) / 2;
        
        oWnd=window.open(strURL,"Echox","location=0,status=0,scrollbars=1,menubar=0,resizable=1,toolbar=0,width=800,height=650");
        
        oWnd.moveTo(top,left); 
        return false; 
        
    }
    catch(err)
    {
       alert(err.message);
    }
}

Open in new window

0
dotnetpro
Asked:
dotnetpro
  • 2
  • 2
1 Solution
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
I test this code in firebug. Everything is ok in mine browser so I think that there is other problem not related with this script, or you have very restrictive browser setting.

function openReportWindow(strURL) 
{
    try
    {
    
        var top = (window.screen.height - 580) / 2;
        var left = (window.screen.width - 1000) / 2;
        
        oWnd=window.open(strURL,"Echox","location=0,status=0,scrollbars=1,menubar=0,resizable=1,toolbar=0,width=800,height=650");
        
        oWnd.moveTo(top,left); 
        return false; 
        
    }
    catch(err)
    {
       alert(err.message);
    }
}
 
openReportWindow('http://test');

Open in new window

0
 
bluV11tCommented:
Hi!
Tested the code in IE8 and I get an access denied error at oWnd.moveTo(top,left);

This security issue occurs if you try to access a window where the document (url) is on a different domain.
0
 
dotnetproAuthor Commented:
Do you guys think there is a bettter way or just way to tell the user to allow pop up s from only this site. Any alert message would you think ?
0
 
bluV11tCommented:
Hi!
Just remove the line oWnd.moveTo(top,left);  and you should be fine :-)
0
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
Better way? do you really need to open new window ? Maybe opeing a div with Iframe will be a solution for you ? ^^ just think about it - users dont like to have new windows open ... :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now