I try to reload my jqgrid after click on the close button in the popup window in IE8. but it gave me several errors and now i tried to reload it in the page itself. meaning that not from the popup window but run a function(resides in main page) upon press the 'close' button in the popup. i am getting an error - 'window.opener.document' is null or not an object.(in IE8) please find my code below -

popup window function -

function closeUserPopup(){

//var x = window.opener.document.getElementById("myjqgrid");
//alert(x);
window.opener.document.callReload(); 
window.close();

}

function in the parent page to reload jqgrid-

function callReload(){
jq("#mygrid").trigger("reloadGrid"); 

}

is there any way to reload the parent page jqgrid from the popup window ? ?( before it get closed) Thanks in advance.

有帮助吗?

解决方案


It's not window.opener.document but window.opener
Try to check if the opener is still valid before.
I usually do something like this:

if ( window.opener != null)
   window.opener.callReload();
window.close(); 

A little suggestion.
I've given up with popups like these cause they're hard to manage.
I tend to use a jQuery UI Dialog so I can manage everything on the same page.

UPDATE

If you're using window.showModalDialog(); things are even more simple.
Here's an example:

<script type="text/javascript">
    function OpenDialog(userPopupUrl)
    {
        alert("starting!");
        var vReturnValue = window.showModalDialog(userPopupUrl,"dialogWidth:450px;dialogHeight:100­px;center:yes;resizable:no;status:no;help:no;");
        alert("I am here!");
        // You can refresh whatever you want here!!!!
    }
</script>

Since you're creating a dialog the client-script process stops until you close the popup window. At that point, your javascript gets the control back and can fire some other actions. PS: You can use - as I did - a return value as state here.

其他提示

Probably not best practice, but:

(function () {
    var parentLocation = window.opener.location;
    window.opener.location = parentLocation;
})();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top