我正在使用厚盒,并希望在厚盒关闭时刷新父页面。我使用下面的代码,但它有时可以工作,但在某些情况下不起作用......它有什么问题?
<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");?>"/>
最佳答案
也许是因为您在 JavaScript 执行之前提交了表单?如果您想提交表单然后执行 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();
});
});
关于javascript - 我的代码在某些情况下不会刷新父页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25441233/