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>

meks
  • 777
  • 3
  • 12
  • 23
  • http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript – btevfik Apr 21 '13 at 04:28
  • where do you call the function from? a button etc? can you show it, too – İsmet Alkan Apr 21 '13 at 04:30
  • http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript/506004#506004 – Chris M Apr 21 '13 at 04:31
  • window.location.assign works too, please refer to http://www.w3schools.com/jsref/met_loc_assign.asp before pasting possible duplicate. the question link doesn't have location.assign method – İsmet Alkan Apr 21 '13 at 04:33
  • No I just placed this piece of code in the page – meks Apr 21 '13 at 04:37
  • 1
    please paste the full code. – İsmet Alkan Apr 21 '13 at 04:40
  • @IsmetAlkan: If w3schools says that something works, is that a good reason to think it *does* work, or a good reason to think it *doesn't*? :-P – ruakh Apr 21 '13 at 04:42
  • I took this piece of code from w3schools but it doesn't work in my case – meks Apr 21 '13 at 04:43
  • @ruakh - MDN also documents the `.assign()` method. – nnnnnn Apr 21 '13 at 04:43
  • @ruakh I didn't say w3schools isn't to be trusted. people were pasting a similar question from stackoverflow, which doesn't include "window.location.assign". What I say to COMMENTERS is: refer to w3schools, make sure question askers line is wrong, and then paste the question link. – İsmet Alkan Apr 21 '13 at 04:46
  • @meks - do you get any errors in your browser's console? Are you running that code from inside a frame? – nnnnnn Apr 21 '13 at 04:47
  • no. no any errors. yes, it's aspx page – meks Apr 21 '13 at 04:49
  • @meks please paste the whole code if you can :) – İsmet Alkan Apr 21 '13 at 04:50
  • just a moment. I will paste the whole thing – meks Apr 21 '13 at 04:55
  • @IsmetAlkan: I know *you* didn't say that w3schools isn't to be trusted: *I'm* saying it! W3schools isn't to be trusted. The site is garbage from one end to the other, and to link to it is to sacrifice credibility. – ruakh Apr 21 '13 at 05:49
  • please debug your page with firebug, and paste the console results here. – İsmet Alkan Apr 21 '13 at 05:58
  • I think you javascript lines doesn't have any problems. I think you might have problems with "WL Events". – İsmet Alkan Apr 21 '13 at 08:52

4 Answers4

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/

btevfik
  • 3,391
  • 3
  • 27
  • 39
  • I don't see why `.assign()` is necessary. Why not just manually assign it? `window.location = "http://www.example.com/"` – Jace Cotton Apr 21 '13 at 04:46
  • @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. – btevfik Apr 21 '13 at 04:48
  • 1
    @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. – İsmet Alkan Apr 21 '13 at 04:48
  • the problem i can't assign it to click – meks Apr 21 '13 at 05:40
  • @meks is your authLogin function working? place a console.debug statement and see if it works – btevfik Apr 21 '13 at 06:32
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/'">
Jace Cotton
  • 2,004
  • 1
  • 21
  • 38
1

document.location = "www.google.es"

Fosfor
  • 331
  • 2
  • 3
  • 15
1

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

İsmet Alkan
  • 5,361
  • 3
  • 41
  • 64