en.javascript.info/2-ui/2-events/04-default-browser-action/2-catch-link-navigation/solution.view/index.html
2019-11-26 19:26:28 +05:30

40 lines
800 B
HTML

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style>
#contents {
padding: 5px;
border: 1px green solid;
}
</style>
</head>
<body>
<fieldset id="contents">
<legend>#contents</legend>
<p>
How about to read <a href="https://wikipedia.org">Wikipedia</a> or visit <a href="https://w3.org"><i>W3.org</i></a> and learn about modern standards?
</p>
</fieldset>
<script>
contents.onclick = function(event) {
function handleLink(href) {
let isLeaving = confirm(`Leave for ${href}?`);
if (!isLeaving) return false;
}
let target = event.target.closest('a');
if (target && contents.contains(target)) {
return handleLink(target.getAttribute('href'));
}
};
</script>
</body>
</html>