设为首页、添加收藏

代码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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值