4

How to determine if an annual overload was caused by clicking a link in Chrome

 2 years ago
source link: https://www.codesd.com/item/how-to-determine-if-an-annual-overload-was-caused-by-clicking-a-link-in-chrome.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to determine if an annual overload was caused by clicking a link in Chrome

advertisements

The problem is as follows.

onbeforeunload works like a charm in Firefox and has e.explicitOriginalTarget.activeElementthat shows what element has been clicked to cause it.

window.onbeforeunload = function(e){
if (e.explicitOriginalTarget.activeElement){
    return;
}

In Chrome the 'e' object looks identical when you close the window or click the link. Is there any way to determine the target in chrome?


No. The target of the event is the window or document, not the link. Unlike Firefox, Chrome provides no helpful bonus properties on the event object. Your best bet may be to have an click event handler on the body that examines the event target to see if it's a link, but that's not foolproof: the link may have its own click event handler that prevents the default action, or the user may follow the link using the keyboard, in which case no click event will be fired.


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK