设为首页和添加收藏的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>
相关文档:
WebService文件:
[WebMethod]
public int DoMulti(int num1,int num2)
{
int result;
result = num1 * num2;
return result;
}
ASPX文件:
<%@ Page language="c#" Codebehind="Javascript.aspx.cs" AutoEventWireup="false" Inherits=" ......
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional ......
1.使用 使用Response.Write,这种方法会把JS代码写在页面的最顶部(的前面):
2. 使用: page.ClientScript.RegisterStartupScript(); 这种方法会把JS代码嵌入在页面的底部、表单的最后 (前面),适用于要在页面控件加载完成后运行的JS代码
3.使用RegisterClientScriptBlock();这种方法会把JS代码嵌入在页面的顶部、 ......
js验证表单大全
1. 长度限制
<script>
function test()
{
if(document.a.b.value.length>50)
{
alert("不能超过50个字符!");
document.a.b.focus();
return false;
}
}
</script>
<form name=a onsubmit="return test()">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6"&g ......
引自:http://blog.csdn.net/lsj19830812/archive/2007/10/25/1843578.aspx
a.jsp是要打印的页面
<html>
<head>
<script language="javascript">
function fmtPrint(printPlace,w,h){
var sarg=new Array();
var sdata=document.all.item(printPlace);
sarg[0]=s ......