[英]How to redirect a page using javascript
I'm having troubles with a page redirection. 我在页面重定向方面遇到了麻烦。 I have a piece of code which on certain stage of execution suppose to redirect the page to other address. 我有一段代码,在执行的某些阶段,它假定将页面重定向到其他地址。 But for some reason it doesn't. 但是由于某种原因,它不是。
For some reasons I have to use javascript and this is the code I used: 由于某些原因,我必须使用javascript,这是我使用的代码:
window.location.assign("http://www.myaddress.com")
the full code: 完整代码:
<head runat="server">
<title>try mail</title>
<script type="text/javascript">
function openWin() {
myWindow = window.open('myaddressgoeshere', '', 'width=600,height=400');
myWindow.focus();
}
<body>
<form id="form1" runat="server">
<div>
<table width="300px" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> <img src="imagesNew/mail.jpg" width="75" height="52"/></td>
<td> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2" align="center"><div id="signin"></div></td>
</tr>
</table>
</div>
</form>
<script type="text/javascript" language="javascript">
scope = ["wl.signin", "wl.basic", "wl.offline_access", "wl.emails", ],
function id(domId) {
return document.getElementById(domId);
}
WL.Event.subscribe("auth.sessionChange",
function (e) {
if (e.session) {
displayMe();
authLogin();
}
else {
clearMe();
}
}
);
function authLogin(e) {
if (e.status == 'connected') {
WL.Event.unsubscribe("auth.login", authLogin);
window.location.assign("http://www.hotmail.com");
WinJS.Navigation.navigate('files.html');
}
}
</script>
it needs to be in a script
tag 它必须在script
标签中
<html>
<head>
<script>
function newPage()
{
window.location.assign("http://www.example.com")
}
</script>
</head>
<body>
<input type="button" value="click" onclick="newPage()">
</body>
</html>
You don't have to use javascript. 您不必使用javascript。 You can use a meta
element: 您可以使用meta
元素:
<meta http-equiv="refresh" content="0; url='http://www.myaddress.com/'">
document.location =“ www.google.es”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.