0

This is my code.My prblem is that when i click on button the window.open function work properly and it show a popup window but after this,page cannot redirect to define location:

<script type="text/javascript">
    var win=null;

    $(document).ready(function() {

        $("#buttonid").live("click",function(){

            var alt = "http://www.testhost.com/test.php";
            var rel = "http://www.testhost.com/test2.php";               
                var width= (window.innerWidth)-450;
                var win = window.open(alt,"mywin","width=450,height="+window.innerHeight+",left="+width+", location=no, menubar=no, status=no, titlebar=no, scrollbars=no");

                win.onload=function(){

                    window.location=rel;
                 }
                 win.blur();
                 //setTimeout(win.focus(), 0);
                 return false;


    });
    });
</script>
</head>
<body>
<button id="buttonid">Click</button>
</body>
Rahul Chipad
  • 2,373
  • 17
  • 20
  • if i dont use win.onload then page redirect but not showing popup window.i want to redirect when popup window load completely – Rahul Chipad Mar 09 '13 at 10:19

2 Answers2

0

You need to specify it as below,

win.onload=function()
{
    window.open.location=rel;
}
Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
0

Take a look at this post: Detecting the onload event of a window opened with window.open

If you are opening a window to a different domain, you will not be able to tie into this event.

That post has several things you can try.

win.addEventListener('load', function () {
    alert('popup loaded');
}, false);

This is a more ideal cross-browser solution (again, it's from that link):

win[win.addEventListener ? 'addEventListener' : 'attachEvent'](
  (win.attachEvent ? 'on' : '') + 'load', function () {
    alert('popup loaded');
}, false
);

EDIT: Just tried the second code snippet in IE10, FF18, and Chrome 25. The onload event worked great, as long as it was pointing to a URL that was on the same domain as the site calling it. Even I pointed the URL to www.google.com, my event never fired. This is a security feature of the browsers, and I don't think you'll be able to do much about it...

Community
  • 1
  • 1
Adam Plocher
  • 13,994
  • 6
  • 46
  • 79