JS跳转页面参考代码大全

JS跳转页面参考代码
第一种:
<script language="javascript" type="text/javascript">
window.location.href="login.jsp?backurl="+window.location.href;
</script>
第二种:
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
第三种:
<script language="javascript">
window.navigate("top.jsp");
</script>
第四种:
<script language="JavaScript">
self.location=’top.htm’;
</script>
第五种:
<script language="javascript">
alert("非法访问!");
top.location=’xx.jsp’;
</script>

=====javascript中弹出选择框跳转到其他页面=====
<script language="javascript">
<!--
function logout()...{
if (confirm("你确定要注销身份吗?是-选择确定,否-选择取消"))...{
window.location.href="logout.asp?act=logout"
}
}
-->
</script>


=====javascript中弹出提示框跳转到其他页面=====
<script language="javascript">
<!--
function logout()...{
alert("你确定要注销身份吗?");
window.location.href="logout.asp?act=logout"
}
-->
</script>

=================================
按钮式:
<INPUT name="pclog" type="button" value="GO" onClick="location.href='http://www.51wisdom.com.cn/'">

  链接式:

  <a href="javascript:history.go(-1)">返回上一步</a>

  <a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一步</a>

  直接跳转式:

  <script>window.location.href='http://www.51wisdom.com.cn/';</script>

  开新窗口:

  <a href="javascript:" onClick="window.open(http://www.51wisdom.com.cn/','','height=500,width=611,scrollbars=yes,status=yes')">杭州威士顿网络科技有限公司 </a>

js跳转到页面
自己的:

function toUrl(ul){
if("" == ul || null==ul){
alert("感谢关注");
}else{

window.open(ul);//这是跳出新的窗口

// window.location.href=ul;//这是直接在当前页跳转


}
return;
}
其他的网上的:(有重复)


1.在原来的窗体中直接跳转用
window.location.href="你所要跳转的页面";
2、在新窗体中打开页面用:
window.open('你所要跳转的页面');

window.history.back(-1);返回上一页


3、一些用法
按钮式:
<INPUT name="pclog" type="button" value="/GO" onClick="location.href='连接地址'">
链接式:<a href="javascript:history.go(-1)">返回上一页</a>
<a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一页</a>
直接跳转式:
<script>window.location.href='连接地址';</script>
开新窗口:
<a href="/javascript:" onClick="window.open('连接地址','','height=500,width=611,scrollbars=yes,status =yes')">123</a>


<SCRIPT>
<!--
window.open

('page.html','newwindow','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,

resizable=no,location=no, status=no')
//写成一行
-->
</SCRIPT>

  脚本运行后,page.html将在新窗体newwindow中打开,宽为100,高为400,距屏顶0象素,屏左0象素,无工

具条,无菜单条,无滚动条,不可调整大小,无地址栏,无状态栏。请对照。
  上例中涉及的为常用的几个参数,除此以外还有很多其他参数,请见四。

四、各项参数
  其中yes/no也可使用1/0;pixel value为具体的数值,单位象素。

参数 | 取值范围 | 说明

alwaysLowered | yes/no | 指定窗口隐藏在所有窗口之后
alwaysRaised | yes/no | 指定窗口悬浮在所有窗口之上
depended | yes/no | 是否和父窗口同时关闭
directories | yes/no | Nav2和3的目录栏是否可见
height | pixel value | 窗口高度
hotkeys | yes/no | 在没菜单栏的窗口中设安全退出热键
innerHeight | pixel value | 窗口中文档的像素高度
innerWidth | pixel value | 窗口中文档的像素宽度
location | yes/no | 位置栏是否可见
menubar | yes/no | 菜单栏是否可见
outerHeight | pixel value | 设定窗口(包括装饰边框)的像素高度
outerWidth | pixel value | 设定窗口(包括装饰边框)的像素宽度
resizable | yes/no | 窗口大小是否可调整
screenX | pixel value | 窗口距屏幕左边界的像素长度
screenY | pixel value | 窗口距屏幕上边界的像素长度
scrollbars | yes/no | 窗口是否可有滚动栏
titlebar | yes/no | 窗口题目栏是否可见
toolbar | yes/no | 窗口工具栏是否可见
Width | pixel value | 窗口的像素宽度
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上

=====================================================

【1、最基本的弹出窗口代码】
  其实代码非常简单:


<SCRIPT LANGUAGE="javascript">
<!--
window.open ('page.html')
-->
</SCRIPT>
  因为着是一段javascripts代码,所以它们应该放在<SCRIPT LANGUAGE="javascript">标签和</script>之间

。<!-- 和 -->是对一些版本低的浏览器起作用,在这些老浏览器中不会将标签中的代码作为文本显示出来。要养

成这个好习惯啊。
  Window.open ('page.html') 用于控制弹出新的窗口page.html,如果page.html不与主窗口在同一路径下,

前面应写明路径,绝对路径(http://)和相对路径(../)均可。用单引号和双引号都可以,只是不要混用。
  这一段代码可以加入HTML的任意位置,<head>和</head>之间可以,<body>间</body>也可以,越前越早执行

,尤其是页面代码长,又想使页面早点弹出就尽量往前放。

【2、经过设置后的弹出窗口】

  下面再说一说弹出窗口的设置。只要再往上面的代码中加一点东西就可以了。
  我们来定制这个弹出的窗口的外观,尺寸大小,弹出的位置以适应该页面的具体情况。


<SCRIPT LANGUAGE="javascript">
<!--
window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no,

menubar=no, scrollbars=no, resizable=no,location=no, status=no')
//写成一行
-->
</SCRIPT>
参数解释:
<SCRIPT LANGUAGE="javascript"> js脚本开始;
window.open 弹出新窗口的命令;
'page.html' 弹出窗口的文件名;
'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空'代替;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;

width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
//写成一行
OpenWindow.document.write("<TITLE>例子</TITLE>")
OpenWindow.document.write("<BODY BGCOLOR=#ffffff>")
OpenWindow.document.write("<h1>Hello!</h1>")
OpenWindow.document.write("New window opened!")
OpenWindow.document.write("</BODY>")
OpenWindow.document.write("</HTML>")
OpenWindow.document.close()}
</SCRIPT>
</head>
<body>
<a href="#" οnclick="openwin()">打开一个窗口</a>
<input type="button" οnclick="openwin()" value="打开窗口">
</body>
</html>
  看看 OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照格式写更多的行即可。千万注意多一个标签或少一个标签就会出现错误。记得用OpenWindow.document.close()结束啊。

【9、终极应用--弹出的窗口之Cookie控制】
  回想一下,上面的弹出窗口虽然酷,但是有一点小毛病(沉浸在喜悦之中,一定没有发现吧?)比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),那么每次刷新这个页面,窗口都会弹出一次,是不是非常烦人?:-(有解决的办法吗?Yes! ;-) Follow me. 我们使用cookie来控制一下就可以了。首先,将如下代码加入主页面HTML的<HEAD>区:
<script>
function openwin()
{window.open("page.html","","width=200,height=200")}
function get_cookie(Name)
{var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset,end))
}
}
return returnvalue;
}
function loadpopup(){
if (get_cookie('popped')=='){
openwin()
document.cookie="popped=yes"
}
}
</script>
  然后,用<body οnlοad="loadpopup()">(注意不是openwin而是loadpop啊!)替换主页面中原有的<BODY>这一句即可。你可以试着刷新一下这个页面或重新进入该页面,窗口再也不会弹出了。真正的Pop-Only-Once!

--------------------------------------------------

第一种:
<script language="javascript" type="text/javascript">
window.location.href="login.jsp?backurl="+window.location.href;
</script>

第二种:
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>

第三种:
<script language="javascript">
window.navigate("top.jsp");
</script>

第四种:
<script language="JavaScript">
self.location='top.htm';
</script>

第五种:
<script language="javascript">
alert("非法访问!");
top.location='xx.jsp';
</script>

-----------------------------------------------------------

第一种:
<script language="javascript" type="text/javascript">
window.location.href="login.jsp?backurl="+window.location.href;
</script>
第二种:
<script language="javascript">
alert("返回");
window.history.back(-1);
</script>
第三种:
<script language="javascript">
window.navigate("top.jsp");
</script>
第四种:
<script language="JavaScript">
self.location=’top.htm’;
</script>
第五种:
<script language="javascript">
alert("非法访问!");
top.location=’xx.jsp’;
</script>

=====javascript中弹出选择框跳转到其他页面=====
<script language="javascript">
<!--
function logout()...{
if (confirm("你确定要注销身份吗?是-选择确定,否-选择取消"))...{
window.location.href="logout.asp?act=logout"
}
}
-->
</script>


=====javascript中弹出提示框跳转到其他页面=====
<script language="javascript">
<!--
function logout()...{
alert("你确定要注销身份吗?");
window.location.href="logout.asp?act=logout"
}
-->
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
软件登录及跳转页面开发的代码需要根据具体的开发语言和框架来进行编写,下面以常见的Web开发为例: 1. 登录页面代码(HTML、CSS、JavaScript): ```html <!DOCTYPE html> <html> <head> <title>Login</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="login-container"> <h1>Login</h1> <form> <label for="username">Username:</label> <input type="text" id="username" name="username"> <label for="password">Password:</label> <input type="password" id="password" name="password"> <input type="submit" value="Login" onclick="login()"> </form> </div> <script src="script.js"></script> </body> </html> ``` ```css .login-container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } form { display: flex; flex-direction: column; align-items: center; justify-content: center; margin-top: 20px; } label { margin-top: 10px; } input[type="text"], input[type="password"] { width: 200px; height: 30px; margin-top: 5px; margin-bottom: 10px; text-align: center; border-radius: 5px; } input[type="submit"] { width: 100px; height: 30px; margin-top: 10px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; } input[type="submit"]:hover { background-color: #3e8e41; } ``` ```javascript function login() { event.preventDefault(); // 阻止表单的默认提交行为 var username = document.getElementById("username").value; var password = document.getElementById("password").value; // 发送登录求,验证用户名和密码 // 如果验证通过,跳转到首页 // 如果验证不通过,提示错误信息 if (username === "admin" && password === "123456") { window.location.href = "home.html"; } else { alert("Invalid username or password!"); } } ``` 2. 首页代码(HTML、CSS): ```html <!DOCTYPE html> <html> <head> <title>Home</title> <link rel="stylesheet" type="text/css" href="style.css"> </head> <body> <div class="home-container"> <h1>Welcome to the home page!</h1> <p>This is the content of the home page.</p> <button onclick="logout()">Logout</button> </div> <script src="script.js"></script> </body> </html> ``` ```css .home-container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } button { margin-top: 20px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; cursor: pointer; } button:hover { background-color: #3e8e41; } ``` ```javascript function logout() { // 发送注销求,清空登录状态 // 跳转到登录页面 window.location.href = "login.html"; } ``` 以上代码仅供参考,实际开发中需要根据具体要求进行调整和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值