You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/ui/utils/emulateAnchorClick.js

20 lines
464 B
JavaScript

5 years ago
/**
*
* @param {Event} ev
* @param {String} targetUrl
* @param {Boolean} alwaysOpenInNewWindow
*/
export default function emulateAnchorClick(ev, targetUrl, alwaysOpenInNewWindow = false) {
let openInNewWindow;
if (alwaysOpenInNewWindow) {
openInNewWindow = true;
} else {
openInNewWindow = (ev.ctrlKey || ev.shiftKey || ev.metaKey);
}
if (openInNewWindow) {
window.open(targetUrl);
} else {
window.location.href = targetUrl;
}
}