设为首页和添加收藏的Javascript代码
设为首页和添加收藏的Javascript代码,兼容性还可以,各种主流浏览器都测试通过了。
function addfavorite(){//加入收藏
if (document.all){
window.external.addFavorite("http://"+document.location.host+"/",document.title);
}else if (window.sidebar){
window.sidebar.addPanel(document.title,"http://"+document.location.host+"/", "");
}
}
//设为首页IE下可以,其他浏览器不稳定。
function addhomepage(){if(document.all){document.body.style.behavior='url(#default#homepage)';document.body.setHomePage('http://'+document.location.host+'/');}else{document.body.setHomePage('http://'+document.location.host+'/');}}
//推荐使用。
function SetHomepage(){//设为首页
if(document.all){
document.body.style.behavior="url(#default#homepage)";
document.body.setHomePage("http://"+document.location.host+"/");
}
else if(window.sidebar){
if(window.netscape){
try{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch(e){
alert("您的浏览器未启用[设为首页]功能,开启方法:先在地址栏内输入about:config,然后将项 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://"+document.location.host+"/");
}
}
<a href="javascript:void(0)" mce_href="javascript:void(0)" onclick="SetHomepage()">设为首页</a>
<a href="javascript:void(0)" mce_href="javascript:void(0)" onclick="addfavorite()">加入收藏</a>
相关文档:
JavaScript CSS Style属性对照表
文章来源:http://www.phplamp.org/2008/10/jsavscript-js-css-style/
为了达到某种特殊的效果我们需要用Javascript动态的去更改某一个标签的Css属性。比如:鼠标经过一个图片时我们让图片加一个边框,代码可能是这样:
JavaScript代码
<script type="text/javascript"> & ......
avaScript通过内置的setTimeout函数来完成页面内的定时检查,也是很久以前写的东西了。
之所以想起它来,是因为在和项目组其他成员说该事情的时候,别人竟然嘲笑我说是上个世纪的代码,现在都用WEB2.0了。
<script language="JavaScript" type="text/JavaScript">
//增加系统扫描时间
var v_ ......
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>JS调用现成Word模板完成打印</title>
<script type="text/javascript">
//转换word的函数
function ......