简体   繁体   English

防止刷新父页面

[英]Preventing parent page from refresh

I have created popup window in asp.net when i click on submit button of popup window my parent page get refresh. 当我单击弹出窗口的提交按钮时,我在asp.net中创建了弹出窗口,父页面得到刷新。 how i can prevent it to refresh. 我如何防止它刷新。 I have written code to refresh page on close event but not on submit but it get refresh on submit. 我已编写代码以在关闭事件时刷新页面,但在提交时不刷新,但是在提交时刷新。

`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';
    }`

Thanks. 谢谢。

Submit button always send request to server , so default it refresh the page. 提交按钮总是向服务器发送请求 ,因此默认情况下刷新页面。 To overcome this issue, you can define it as simple button Or you have below solutions in Jquery Click event code: 要解决此问题,可以将其定义为简单按钮,或者在Jquery Click事件代码中具有以下解决方案:

(1) return false; //at last statement of your code which not allow page to refresh
(2) use event.PreventDefault()

window.onbeforeunload gets triggered in case of submit too, so set location.href to refresh parent page just before window.close() . 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.

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