0

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:

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>&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>

17

4 Answers 4

2

You don't have to use javascript. You can use a meta element:

<meta http-equiv="refresh" content="0; url='http://www.myaddress.com/'">
Sign up to request clarification or add additional context in comments.

3 Comments

he said for some reason i have to use javascript. so i am assuming this is not what he wants but this is more logical if you just want to redirect from a page.
Ooh, he wants it to redirect onclick?
@meks please paste this: "<meta http-equiv="refresh" content="0; url='myaddress.com'">" between your "<head>" tags.
2

it needs to be in a script tag

<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/

5 Comments

I don't see why .assign() is necessary. Why not just manually assign it? window.location = "http://www.example.com/"
@Jacedc that works too. i don't really know the difference. he was just trying to do this way so i put it that way. he said in the comments "No I just placed this piece of code in the page" so i assumed he literally placed only that piece of line in the page and assumed it would work.
@Jacedc the first tendency here is to correct the present code part with as less change as possible, than to suggest possible better ways, I think.
the problem i can't assign it to click
@meks is your authLogin function working? place a console.debug statement and see if it works
1

document.location = "www.google.es"

Comments

1

Your javascript line has no errors. I think you have a problem somewhere else. Please refer to this link.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.