简体   繁体   中英

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. 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:

(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() .

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

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