代码1:兼容FF收藏
2
3<script type=”text/javascript”>
4// <![CDATA[
5function bookmark(){
6var title=document.title
7var url=document.location.href
8if (window.sidebar) window.sidebar.addPanel(title, url,"");
9else if( window.opera && window.print ){
10var mbm = document.createElement('a');
11mbm.setAttribute('rel','sidebar');
12mbm.setAttribute('href',url);
13mbm.setAttribute('title',title);
14mbm.click();}
15else 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<!–
25function fAddFavorite(sTitle, sURL){
26if(document.all)
27 window.external.AddFavorite(sURL, sTitle);
28else
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。