<script type="text/javascript">
function addFav() { // 加入收藏夹
if (document.all) {
window.external.addFavorite(' http://www.xxx.com'</A>,'网站名称')
}
else if (window.sidebar) {
window.sidebar.addPanel('网站名称', ' http://www.xxx.com'</A>, "")
}
}
function SetHome(obj) {
try {
obj.style.behavior = 'url(#default#homepage)'
obj.setHomePage('网站地址')
} catch (e) {
if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect")
} catch (e) {
alert(" 抱歉,此 *** 作被浏览器拒绝!\n\n请在浏览器地址栏输入“about:config”并回车然后将 [signed.applets.codebase_principal_support]设置为'true'")
}
} else {
alert(" 抱歉,您所使用的浏览器无法完成此 *** 作。\n\n您需要手动将' http://www.xxx.com'</A>设置为首页。")
}
}
}
</script>
<!doctype html><html>
<head>
<title></title>
</head>
<body>
<div>
<a href="/">首页</a>|
<a onclick="SetHome(window.location)" href="javascript:void(0)">设为首页</a>
| <a onclick="AddFavorite(window.location,document.title)" href="javascript:void(0)">加入收藏</a>
</div>
<script type="text/javascript" language="javascript">
//加入收藏
function AddFavorite(sURL, sTitle) {
sURL = encodeURI(sURL)
try{
window.external.addFavorite(sURL, sTitle)
}catch(e) {
try{
window.sidebar.addPanel(sTitle, sURL, "")
}catch (e) {
alert("加入收藏失败,请使用Ctrl+D进行添加,或手动在浏览器里进行设置.")
}
}
}
//设为首页
function SetHome(url){
if (document.all) {
document.body.style.behavior='url(#default#homepage)'
document.body.setHomePage(url)
}else{
alert("您好,您的浏览器不支持自动设置页面为首页功能,请您手动在浏览器里设置该页面为首页!")
}
}
</script>
</body>
</html>
支持ie,ff,chrome,safari,360安全,qq,遨游,搜狗浏览器,不兼容360急速浏览器的加入收藏功能
这两个功能的用途越来越小了,所以没有方法绝对适合所有浏览器的。
PHP 没有相关的功能,不过可以通过javascript脚本来实现加入收藏的js代码如下:
目前兼容IE系列和Firefox,至于其他的浏览器,则d窗提示“用Ctrl+D来加入收藏”。
<script type="text/javascript">
//加入收藏的函数
function bookmark(title, url) {
if(document.all) { // ie
window.external.AddFavorite(url, title)
}else if(window.sidebar) { // firefox
window.sidebar.addPanel(title, url, "")
}else if(window.opera && window.print) { // opera
var elem = document.createElement('a')
elem.setAttribute('href',url)
elem.setAttribute('title',title)
elem.setAttribute('rel','sidebar')
elem.click() // this.title=document.title
}else{
alert("加入收藏失败,请使用Ctrl+D进行添加")
}
}
</script>
加入收藏 HTML 代码调用
设为首页的js代码:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)