从网上找的IE和FF下都兼容的加入收藏的代码
1
很早就发现传统的加入IE收藏夹的代码在Firefox下是无效的。
2
3
4
<a href="javascript:window.external.AddFavorite('http://www.9enjoy.com','9Enjoy')">添加到收藏夹</a>
5
6
7
今天浏览im286,发现讨论两者兼容的代码,调试后,发现可行:)
8
9
第一段:
10
11
12
<script>
13
function addfavorite()
14

{
15
if (document.all)
16
{
17
window.external.addFavorite('http://www.9enjoy.com','9Enjoy');
18
}
19
else if (window.sidebar)
20
{
21
window.sidebar.addPanel('9Enjoy', 'http://www.9enjoy.com', "");
22
}
23
}
24
</script>
25
<a href="#" onclick="addfavorite()">把本博客加入收藏</a>
26
27
28
29
下面一段更严谨,IE6,IE7,FF均通过。
30
31
32
<html>
33
<head>
34
<title>加入收藏</title>
35
<script language="JavaScript" type="text/javascript">
36
function JSAddFavorite()
37

{
38
39
if ( window.sidebar && "object" == typeof( window.sidebar ) && "function" == typeof( window.sidebar.addPanel ) )
40
41
{
42
43
// firefox
44
45
window.sidebar.addPanel( '9Enjoy, 'http://www.9enjoy.com/', '' );
46
47
}
48
49
else if ( document.all && "object" == typeof( window.external ) )
50
51
{
52
53
// ie
54
55
window.external.addFavorite( 'http://www.9enjoy.com/', '9Enjoy' );
56
57
}
58
59
}
60
61
</script>
62
</head>
63
64
<body>
65
<a href="javascript:JSAddFavorite();" title="加入收藏">加入收藏</a>
66
</body>
67
<html>
68
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
注,我使用以上代码在FF上并未执行成功。
这个是我的代码
1
<script language="javascript">
2
function JSAddFavorite()
{
3
if(window.sidebar && "object" == typeof(window.sidebar) && "function"==typeof(window.sidebar.addPanel))
{
4
//firefox
5
window.sidebar.addPanel("收藏标记","http://www.xxxx.com");
6
}
7
else if(document.all && "object" == typeof(window.external))
{
8
//ie
9
window.external.addFavorite("http://www.xxxx.com","收藏标记");
10
}
11
}
12
window.setTimeout("JSAddFavorite",60*1000);
13
</script>
如上,在FF上执行不成功。不知怎么回事?有知道的兄弟评论下。