簡體   English   中英

如何使用JavaScript重定向頁面

[英]How to redirect a page using javascript

我在頁面重定向方面遇到了麻煩。 我有一段代碼,在執行的某些階段,它假定將頁面重定向到其他地址。 但是由於某種原因,它不是。

由於某些原因,我必須使用javascript,這是我使用的代碼:

window.location.assign("http://www.myaddress.com")

完整代碼:

<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>&nbsp;</td>
</tr>
<tr>
<td colspan="2">&nbsp;</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>

它必須在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> 

http://jsfiddle.net/DpwnF/

您不必使用javascript。 您可以使用meta元素:

<meta http-equiv="refresh" content="0; url='http://www.myaddress.com/'">

document.location =“ www.google.es”

您的javascript行沒有錯誤。 我認為您在其他地方有問題。 請參考此鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM