最近觉得还是谈一个老话题--------页面中调用window.external象的一些api进行例如“加入收藏”或者“设为主页”等操作
其实如果你够留意官方文档的话,你会发现这样一句话:
Allows access to an additional object model provided by host applications of the Windows Internet Explorer components.
所以就存在一个很大的问题-------兼容性?当然你能在各种社区里面看到兼容ff的设为首页或者加入收藏的代码。当然还有一些很“牛X”的网站你一打开就给你谈加入收藏夹和各种植入的广告。。。oh。。。。。头疼关之。
- 先认识一下window.external官方提高的文档中包含的部分methods
- AddChannel
--------------Obsolete.Presents a dialog box that enables the user add the specified channel,or to change the channel URL,if it is already installed
2. AddFavorite
--------------Prompts the user with a dialog box to add the specified URL to the Favorites list
window.external.AddFavorite(sURL[,sTitle])
参数有两个第一个是URL地址(非空参数),第二个是收藏的标题(这个可选参数)
window.external.AddFavorite(location.href,document.title);//IE下将当前浏览器地址作为收藏地址
我以前在support.mozilla上面看到兼容代码
function addfavorite(){ if(document.all){ window.external.addFavorite('http://www.baidu.com','百度'); }else if(window.sidebar){ window.sidebar.addPanel('百度','http://www.baidu.com','') ; } }
当然你可能不是很属性sidebar里面的一些api,不要着急我也给你放出来:
window.sidebar.addPanel(title,contentURL,customizeURL)
注意一下:第3个参数设置为空字符串是必要的
当然如果你对火狐比较熟悉的话你应该知道ctr +d也能实现操作
英文官方参考文档http://msdn.microsoft.com/en-us/library/ms535246.aspx
下面的这个设为主页的方法是各个大型门户多在采用的api
function SetHome(obj){ try{ obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage('http://'); }catch(e){ if(window.netscape){ try{ netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); }catch(e){ alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); } var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); prefs.setCharPref('browser.startup.homepage','http://'); } } }
ps:如果你善于发现的话你会发现百度的首页是这样处理设为主页的
原理就是判断浏览器如果不是ie就display:none;-----------这样的处理方式有点。。。。
<a id="sh" onclick="this.setHomePage('http://www.baidu.com')" href="http://utility.baidu.com/traf/click.php?id=215&url=http://www.baidu.com" onmousedown="return ns_c({'fm':'behs','tab':'homepage','pos':0})">把百度设为主页</a>
isIE=n.userAgent.indexOf("MSIE")!=-1&&!window.opera, sh=d.getElementById("sh"); //sh为a标签的id if(isIE&&sh&&!sh.isHomePage("http://www.baidu.com")){ sh.style.display="inline" }
相关推荐
window.clearInterval与window.setInterval的用法.
window.open()对于各浏览器兼容情况
window.showModalDialog以及window.open用法简介
弹出窗口,并且弹出窗口要求最大化处理,window.open打开的窗口获取到焦点
作为发起端,我们可以open一个新窗口,或创建一个iframe,往新窗口里发送数据,简单起见,我们每6秒钟发送一次,然后创建消息监听器,从目标窗口监听它反馈的信息。 //弹出一个新窗口 var domain = '...
对window.open进行封装, 使其更好用, 且更兼容, 很多人说window.open不兼容,其实不是, 因为不能直接执行, 必须通过用户手动触发才行;看代码: 代码如下 var openWindow = function(url, options) { var str = ""; ...
重写window.alert方法 重写window.alert方法
NULL 博文链接:https://shawnfree.iteye.com/blog/598885
window.hlp window.hlpwindow.hlp window.hlp window.hlp
window.showModalDialog以及window.open用法简介
Window.open ('page.html') 用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(../)均可。用单引号和双引号都可以,只是不要混用。 这一段代码...
javascript中window.confirm这个方法很好用,可以弹出一个确认对话框我们之所以弹出这个对话框,可能就是因为该操作很危险,所以要用户确认。但如果默认选择”确定”,则可能违背了这个原则。 另外,confirm对话框的...
window.request window.fetch 的别名将window.fetch别名为window.request “大脑 polyfill”。 老实说, 听起来不太 。 “Fetch”听起来就像您只是在执行GET请求。 我们习惯于谈论请求和响应。 的实际上说了 9 次...
window.event.keycode值大全,内含javascript中所有键盘键值,查找方便简单。
window.location.href页面跳转的用法(区别于redirect)
This is a `window.showModalDialog()` shim using a modal HTML5 `<dialog>` element and ECMAScript 6 Generators. It was tested in the latest Google Chrome with the *Enable Experimental JavaScript* flag ...
扩展window.open方法,使得window.open时针对相同的URL地址非打开新窗口,而是仅仅激活已存在窗口,另外,此激活不会刷新页面,不会丢失页面上已存在的数据
关于window.open的一些特性,一些你经常不注意的,值的一看啊
window.name解决跨域问题的文档,刚才网上发现的.也许有点作用