-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
92 lines (84 loc) · 2.69 KB
/
index.html
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>我的在线书签</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 20px;
}
h1 {
margin-bottom: 20px;
}
.button-container {
margin-bottom: 20px;
}
button {
padding: 10px 20px;
margin: 5px;
font-size: 16px;
border: none;
cursor: pointer;
background-color: #007bff;
color: white;
border-radius: 5px;
}
button:hover {
background-color: #0056b3;
}
iframe {
width: 90%;
height: 600px;
border: 1px solid #ddd;
}
</style>
</head>
<body>
<h1>我的在线书签</h1>
<!-- 按钮切换书签 -->
<div class="button-container">
<button id="chromeButton">🌐 Chrome 书签</button>
<button id="firefoxButton">🔥 火狐书签</button>
</div>
<!-- 默认加载 Chrome 书签 -->
<iframe id="bookmarkFrame" src="Chrome-bookmarks.html"></iframe>
<script>
function switchBookmarks(type) {
var iframe = document.getElementById("bookmarkFrame");
if (type === 'chrome') {
iframe.src = "Chrome-bookmarks.html";
} else if (type === 'firefox') {
iframe.src = "Firefox-bookmarks.html";
}
}
function setIframeLinksBlank() {
var iframe = document.getElementById('bookmarkFrame');
try {
var links = iframe.contentWindow.document.querySelectorAll('a');
links.forEach(function(link) {
link.setAttribute('target', '_blank');
});
} catch (e) {
console.log("无法访问iframe内容,可能是跨域问题", e);
}
}
window.onload = function() {
var iframe = document.getElementById('bookmarkFrame');
// iframe加载完成后,设置所有链接 target="_blank"
iframe.addEventListener('load', function() {
setIframeLinksBlank();
});
// 按钮事件绑定
document.getElementById('chromeButton').addEventListener('click', function() {
switchBookmarks('chrome');
});
document.getElementById('firefoxButton').addEventListener('click', function() {
switchBookmarks('firefox');
});
};
</script>
</body>
</html>