开发者

How to implement onbeforeunload behavior for a div?

I posted recently regarding onbeforeunload implementation. Its working now but that only solved half of the problem. My application has lot of tabs and I want to throw this same confirmation to user if he clicks on a new tab without saving changes. all the tabs are div elements. How do you implement something of this sort? Sa开发者_JAVA技巧mple tab structure is attached, where every tab loads a new page.

How to implement onbeforeunload behavior for a div?


Something like this would help you. You need to add the clickHandler to each tab click event.

var dirty = false;

function clickHandler(){
     if (dirty && confirm('you are leaving the tab, wanna stay and save?')){
         return false; //prevent default
     }
     else {
         dirty = false;
         //trigger your tab load
     }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜