2013-10-17 50 views

回答

1

您可以使用查询字符串javascript函数从here

window.location.href = getParameterByName("path"); 

function getParameterByName(name) { 
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), 
     results = regex.exec(location.search); 
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); 
} 
+0

还是不行对我来说...例如:http://www.mywebsite.com/myfolder/redir.html?path=http:/ /www.google.com/不会将我重定向到谷歌。 –

0

JavaScript函数来获取查询参数:

function get_query_param(name) { 
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), 
     results = regex.exec(location.search); 
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); 
} 

window.onload = function() { 
    if (get_query_param('path') != null) 
     alert(get_query_param('path')); 
} 

希望帮助