2011-05-09 40 views
0
頁面

我有一個非常簡單的「頁」:無法獲得Javascript來瀏覽到

<html> 
<head> 
</head> 
<body>Handling... 

<script> 
var token = location.hash.toString().substring("#access_token=".length, location.hash.indexOf("&")); 
var t = "/ri/auth/fbLogin?token=" + encodeURIComponent(token); 
console.log(t); 
// t is now /ri/auth/fbLogin?token=blablablablablabla 
setTimeout(function() { 
window.location.href = t; 
}, 2000); 
</script> 

</body></html> 

出於某種原因,該腳本總是重定向到本身的第一次,但沒有#。該版本的腳本然後重定向到預期的URL,但是有一個空的token

我試過window.location = twindow.navigate(t),但沒有運氣。這個超時也是失敗的嘗試。

回答

0

多麼愚蠢。事實證明,腳本畢竟工作,但它導航的頁面被重定向回推薦人。

0

嘗試將 var token = location.hash.toString()。substring(「#access_token =」。length,location.hash.indexOf(「&」)); var t =「/ ri/auth/fbLogin?token =」+ encodeURIComponent(token);

超時功能。

+0

我不認爲這會有所幫助。通過'console.log',我發現't'的值是正確的。 – 2011-05-09 21:03:28

+0

t的值是正確的是的,但它可能是一個範圍問題,因爲你沒有在setTimeout內傳遞任何東西給你的函數,在這種情況下,我沒有看到你不能將代碼放在那裏。 – Darren 2011-05-09 21:04:32