-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlink.html
More file actions
42 lines (38 loc) · 1.56 KB
/
link.html
File metadata and controls
42 lines (38 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<body>
<div id="contents">
<a name="list">the list</a>
<ul>
<li><a href="http://google.com">http://google.com</a></li>
<li><a href="/tutorial">/tutorial.html</a></li>
<li><a href="local/path">local/path</a></li>
<li><a href="ftp://ftp.com/my.zip">ftp://ftp.com/my.zip</a></li>
<li><a href="http://nodejs.org">http://nodejs.org</a></li>
<li><a href="http://internal.com/test">http://internal.com/test</a></li>
</ul>
</div>
<script>
// let links = document.querySelectorAll('[href]')
// for (let link of links) {
// if (link.getAttribute('href').includes('://') ) {
// link.style.color = 'orange'
// console.log(link.getAttribute('href'))
// }
// if (link.getAttribute('href').startsWith('http://internal.com') ) {
// link.style.color = ''
// }
// }
contents.onclick = function (event) {
function handleLink(href) {
let isLeaving = confirm(`Вы хотите перейти по сслыке ${href}?`);
if (!isLeaving) return false;
}
let target = event.target.closest('a');
if (target && contents.contains(target)) {
return handleLink(target.getAttribute('href'));
}
};
let selector = 'a[href*="://"]:not([href^="http://internal.com"])'
let links = document.querySelectorAll(selector)
links.forEach(link => link.style.color = 'orange')
</script>
</body>