代码1:兼容FF收藏
2
3
<script type=”text/javascript”>
4
// <![CDATA[
5
function bookmark(){
6
var title=document.title
7
var url=document.location.href
8
if (window.sidebar) window.sidebar.addPanel(title, url,"");
9
else if( window.opera && window.print ){
10
var mbm = document.createElement('a');
11
mbm.setAttribute('rel','sidebar');
12
mbm.setAttribute('href',url);
13
mbm.setAttribute('title',title);
14
mbm.click();}
15
else if( document.all ) window.external.AddFavorite( url, title);
16
}
17
// ]]>
18
</script>
19
<a href=”javascript:bookmark()”>添加收藏</a>
20
21
代码2:兼容FF/IE7收藏
22
23
<script type=”text/javascript”>
24
<!–
25
function fAddFavorite(sTitle, sURL){
26
if(document.all)
27
window.external.AddFavorite(sURL, sTitle);
28
else
29
window.sidebar.addPanel(sTitle, sURL, “”);
30
}
31
//–>
32
</script>
33
<a href=”#” onclick=”fAddFavorite(’在线代理’,'http://www.vstime.com’);”>添加收藏</a>
34
35
代码3:兼容FF/IE设为首页
36
37
<a href=”#” onClick=”this.style.behavior=’url(#default#homepage)’;this.setHomePage(’http://www.vstime.com/’);return(false);” style=”behavior: url(#default#homepage)”>设为首页</a>
38
另一种方法,后台代码:
要获得收藏加目录我们可以用GetFolderPath方法来完成,代码如下
string path=Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites);要创建快捷方式需要用到IWshRuntimeLibrary命名空间
,在这里我们要USING一下。并在引用里添加一个COM,windows script host object model。添加到收藏夹方法如下“
public void addFavorites(string url,string filename,string savepath)
{
string path=Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites);
if(!System.IO.File.Exists(path+"/"+filename+savepath+".url"))
{
IWshShell_Class shell = new IWshShell_ClassClass();
IWshURLShortcut shortcut=null;
if(savepath=="Favorites")
{
shortcut = shell.CreateShortcut(Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites)+"/"+filename+".url") as IWshURLShortcut;
}
else
{
shortcut = shell.CreateShortcut(Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites)+"/"+savepath+"/"+filename+".url") as IWshURLShortcut;
}
shortcut.TargetPath = url;
shortcut.Save();
}
}
其中URL是你要保存网页的路径,filename是生成快捷方式的名称,savepath是在收藏夹中保存在哪个目录。
顺便想提个问题,有谁知道如何得到AxWebBrowser对象中statustext。



4314

被折叠的 条评论
为什么被折叠?



