开发者

Asking confirmation before page unload, using window.onbeforeunload

On my parent page I added a script which ask confirmation befor page unload (On every button press) using window.onbeforeunload, The problem i use to open a subPage on this parent page, and on closing of开发者_JAVA技巧 the subpage i use to reload the parent page, but it ask confirmation and I dnt want that....

Any help will be really appreciated

Thanx


How about...

  1. In the main page, creat a new variable, called 'confirmUnload', set it to 'true' by default.
  2. In the beforeUnload function, check the state of this variable before deciding whether to ask for confirmation or not.
  3. Add a new function called 'refreshWithoutConfirmation' and have this set the variable to 'false' before refreshing the page.
  4. Have the sub page call 'refreshWithoutConfirmation' instead of refreshing the page directly.

Not tested this, but it seems workable to me.


Before calling reload, set a flag.
In onbeforeunload, check the flag, and, if it's true, return null.


Add a flag variable on parent page. If it true, ask the confirmation. If false, do not ask.

When you close the subPage and before reload the parent, set this flag to false

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜