javascript - js window escape effect, please advise

WBOY
Release: 2016-08-04 09:19:38
Original
1351 people have browsed it

To build a backend, the function of editing articles, product requirements, when the user clicks on the editing window to make changes without saving, click anywhere outside the editing window to prevent the default event, and a pop-up window will allow the user to choose whether to save before executing the default event.
After much deliberation, there is no good solution. Please give me an idea.

The main problem is that instead of closing the browser to trigger the pop-up box, it is triggered when clicking on non-editing window parts on the page, and these parts have various binding events, links, etc.

Reply content:

To build a backend, the function of editing articles, product requirements, when the user clicks on the editing window to make changes without saving, click anywhere outside the editing window to prevent the default event, and a pop-up window will allow the user to choose whether to save before executing the default event.
After much deliberation, there is no good solution. Please give me an idea.

The main problem is that instead of closing the browser to trigger the pop-up box, it is triggered when clicking on non-editing window parts on the page, and these parts have various binding events, links, etc.

The original idea was to add a defocus event to the editing window, pop up a custom confirm, and judge whether to execute the default event based on the confirmation selection, but I gave up...
In the end, I could only add a judgment method to each link and event. Pass in the default execution function as the callback parameter
Similar to this

<code><a href="index.php">首页</a></code>
Copy after login

changed to

<code><div id="myconfirm">
    <p>确认离开?</p>
    <button id="yes">是</button><button id="no">否</button>
</div>
<a href="javascript:void(0)">首页</a>
<script>
$('a').click(function(){
    myconfirm(function(){
        window.location.href="index.php";
    },function(){
        return false;
    });
});
function myconfirm(fun_yes,fun_no){
    $('#yes').unbind();
    $('#no').unbind();
    $('#yes').click(function(){
        fun_yes();
    });
    $('#no').click(function(){
        fun_no();
    });
    $('#myconfirm').show();
}
</script></code>
Copy after login

A very popular dialog plug-in,
http://aui.github.io/artDialo...

Listen to browser closing events

Isn’t it possible to bind the onblur event to the editor?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template