answered
2022-06-13 11:09:16 +0800
MDuchemin 2480 ● 1 ● 6
Hi there,
ZK has a window event listener for beforeUnload which triggers when the page navigates away from its current location (i.e. when user clicks a link).
This even does cleanup, sends a "page is not longer active" message to server, and shutdown the the page JS engine.
Even if the link targets "not a document" such as a tel link, mailto link, or document download link, the beforeUnload event will trigger.
This is because the link is evaluated by the browser after triggering the beforeUnload and other "navigation away" workflows on the document.
The browser then makes the decision to not process the link as a link, but with a browser level handler.
The easiest workaround for this used case would be to set a target="_blank" attribute on your link. However, that creates a temporary blank page, which you may not want for user experience.
Another option is to add an iframe to page as well, and use that hidden iframe as the target for that navigation.
This will still trigger the browser workflow with URL processing, without impacting the page.
In both cases, the "new page" (which is not a new page, but a link) will be evaluated by the browser without triggering beforeUnload on the current page.
See fiddle here:
https://zkfiddle.org/sample/2ovmjej/3-Another-new-ZK-fiddle