[英]Get url parameters and redirect to specific url with javascript
How can I redirect to specific url that appear in the url parameter? 如何重定向到出现在url参数中的特定URL?
example: 例:
http://www.mywebsite.com/Code_id.tv/stream.php http://www.mywebsite.com/Code_id.tv/stream.php
I want to get code_id and I will redirect to specific URL. 我想获取code_id,我将重定向到特定的URL。
The result URL will eventually look like this: 结果URL最终将如下所示:
http://www.mynewwebsite.com/tv.php?id=Code_id http://www.mynewwebsite.com/tv.php?id=Code_id
Thanks 谢谢
To split the path to get the code_id: 分割路径以获取code_id:
var url2Process = window.location.pathname;
var patharray = url2Process.split( '/' );
// remove '.tv' or '.movie' or '.whatever' from the end
var code_id_array = patharray[1].split('.');
var code_id = code_id_array[0];
// redirect
window.location = 'http://domain.com/rb/play.php?id=tt' + code_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.