简体   繁体   English

在某些情况下,我的代码无法刷新父页面

[英]My code don't refresh parent page in some cases

I am using a thick box and want to refresh parent page when thicbox is closing. 我使用的是厚框,想在thicbox关闭时刷新父页面。 I use below code but it works sometime and dont work in some situations... waht is the problem with it? 我使用下面的代码,但它有时起作用,在某些情况下不起作用...这是问题所在吗?

<script>
    function close2()
    {
       parent.tb_remove();
       parent.location.reload(1)
    }
</script>

<input type="submit" name="save_new_task" id="save_new_task" onclick="close2()" style="width: 100px;text-align: center;" 
  class="button button-primary button-medium" value="<?Php _e("register","creat_mysite");?>"/>

Maybe it is because your submitting the form before the JavaScript get executed? 也许是因为您在执行JavaScript之前提交了表单? If you want to submit your form and then perform a Javascript function you can try this: 如果要提交表单然后执行Javascript函数,可以尝试以下操作:

$(document).ready(function()
{
    $('#save_new_task').click(function(e)
    {
        e.preventDefault();

        //Serialize your form
        //POST request


        //Maybe also try window.opener instead of parent
        //window.opener refers to the window that called window.open( ... ) to open the window from which it's called
        //window.parent refers to the parent of a window in a <(i)frame>
        window.opener.tb_remove();     
        window.opener.location.reload(); 
    });
});          

i dont know the context but from what i could figure out try the below Try this: 我不知道上下文,但是从我能弄清楚的地方尝试以下尝试此操作:

   <script>
        function close2()
        {
           parent.tb_remove();
           parent.location.reload(1);
return true;
        }
    </script>
    <form onsubmit="return close2()" >
    <input type="submit" name="save_new_task" id="save_new_task" style="width: 100px;text-align: center;"  class="button button-primary button-medium" value="<?Php _e("register","creat_mysite");?>"/>
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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