[英]Preventing parent page from refresh
当我单击弹出窗口的提交按钮时,我在asp.net中创建了弹出窗口,父页面得到刷新。 我如何防止它刷新。 我已编写代码以在关闭事件时刷新页面,但在提交时不刷新,但是在提交时刷新。
`function closeMe() {
window.close();
}
window.onload = function () {
window.opener.document.body.disabled = true;
}
window.onbeforeunload = function () { myUnloadEvent(); }
function myUnloadEvent() {
window.opener.location.href = '../ContentPages/QuoteBuy.aspx';
}`
谢谢。
提交按钮总是向服务器发送请求 ,因此默认情况下刷新页面。 要解决此问题,可以将其定义为简单按钮,或者在Jquery Click事件代码中具有以下解决方案:
(1) return false; //at last statement of your code which not allow page to refresh
(2) use event.PreventDefault()
window.onbeforeunload
也会在submit
时触发,因此将location.href
设置为在window.close()
之前刷新父页面。
function closeMe() {
window.opener.location.href = '../ContentPages/QuoteBuy.aspx';
window.close();
}
window.onload = function () {
window.opener.document.body.disabled = true;
}
window.onbeforeunload = function () { myUnloadEvent(); }
function myUnloadEvent() {
//Do your work
//window.opener.location.href = '../ContentPages/QuoteBuy.aspx';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.