设为首页和收藏代码自动适用IE 其他浏览器弹出提示手动操作

1
2
3
4
5
6
7
8
9
<a href="javascript:;" onclick="setHomepage('http://www.webape.net');">
设为首页
</a>
<a
href="http://www.webape.net"
onclick="addFavorite(this.href, '网猿建站');return false;"
>
收藏本站
</a>
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
<script>
function browserVersion(types) {
var other = 1;
for (i in types) {
var v = types[i] ? types[i] : i;
if (USERAGENT.indexOf(v) != -1) {
var re = new RegExp(v + "(\\/|\\s|:)([\\d\\.]+)", "ig");
var matches = re.exec(USERAGENT);
var ver = matches != null ? matches[2] : 0;
other = ver !== 0 && v != "mozilla" ? 0 : other;
} else {
var ver = 0;
}
eval("BROWSER." + i + "= ver");
}
BROWSER.other = other;
}
var BROWSER = {};
var USERAGENT = navigator.userAgent.toLowerCase();
browserVersion({
ie: "msie",
firefox: "",
chrome: "",
opera: "",
safari: "",
mozilla: "",
webkit: "",
maxthon: "",
qq: "qqbrowser",
rv: "rv",
});
if (BROWSER.safari || BROWSER.rv) {
BROWSER.firefox = true;
}
BROWSER.opera = BROWSER.opera ? opera.version() : 0;
function setHomepage(sURL) {
if (BROWSER.ie) {
document.body.style.behavior = "url(#default#homepage)";
document.body.setHomePage(sURL);
} else {
alert("非 IE 浏览器请手动将本站设为首页", "notice");
}
}
function addFavorite(url, title) {
try {
window.external.addFavorite(url, title);
} catch (e) {
try {
window.sidebar.addPanel(title, url, "");
} catch (e) {
alert("请按 Ctrl+D 键添加到收藏夹");
}
}
}
</script>