简体   繁体   中英

Pop up is not working correct, does not refresh the page

I try to open pop up in the same window, but it forwards me to another. Also, I try to refresh window after pop up closes, but I don't find easy solution. I think the best is not to put # to the URL. That is my function:

<li value="Open window" >
    <a href="javascript: window.open('upd.php?m=<?php echo $oldpar?>','','width=520,height=400')">
        <u>EDIT</u>
    </a>
</li>

I manage open the window, however main page also goes to javascript: window.open('upd.php?m=2','','width=520,height=400') . I tried to put:

<script type="text/javascript">
    <!--
    function refreshParent()
    {
        window.opener.location.href = window.opener.location.href;

        if (window.opener.progressWindow)
        {
            window.opener.progressWindow.close()
        }

        window.close();
    }
    //-->
</script>

It would be great to close pop up automatically after user select variables and press button. Immediately after the parent(main) URL would refresh.. Any help? :)

Ps any ideas how to auto refresh pop up? I saw all browsers have different way of doing that.. Common one?

  • Use "_self" as the window title (second parameter to window.open() ) to open the pop up in the same window.

  • Use window.location.reload(); to reload the current window.

  • Use opener.location.reload(); to reload the window that opened the popup before calling window.close();

I'm not sure, but I guess you've been looking for that.

​<ul>
<li value="Open window" ><a href="javascript: window.open('upd.php?m=<?php echo $oldpar>','','width=520,height=400'); return false;"><u>EDIT</u></a></li>
</ul>

return false; at the end of the call should solve your problem.

UPD:

http://jsfiddle.net/Mt8Vd/

To open the windows via link:

<a href="javascript:open('400','360','account.php?id=<?=$id?>&type=<?=$type?>');">Open</a>

The js function to open a link:

<script language="JavaScript">
function open(w,h,URL)
{
  var width = w;
  var height = h;
  var left = (screen.width/2)-(w/2);
  var top = (screen.height/2)-(h/2);    
  window.open(URL,'janela', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=yes, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');
}
</script>

And Finally in the end of your "popup" you should close the windows after all task get done, just telling the script to close the popup and reload the opener page.

<script language="JavaScript" type="text/javascript">
function close()
{
    opener.location.reload();
    window.close();
}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM