[英]How to change url redirect by Query String in HTML
<meta http-equiv="refresh" content="0; url=http://example.com">
I want to something like this 我想要这样的事情
http://localhost/?url=google.com => google.com http:// localhost /?url = google.com => google.com
I'm guessing you want to split the google.com part from the whole URL. 我猜您想将google.com部分与整个URL分开。 Assign the desired url to a string
将所需的网址分配给字符串
var urlString = "http://localhost/?url=google.com";
Then use the String.split
method to create an array split by the =
sign 然后使用
String.split
方法创建一个用=
号分隔的数组
var splitStringArr = urlString.split("=");
The google.com part would be the second element of the split string array. google.com部分将是分割字符串数组的第二个元素。
console.log(splitStringArr[1])
Output: 输出:
google.com
google.com
let myUrl = 'http://localhost/?url=google.com' if(myUrl.includes('url=')){ let result = myUrl.split('url=')[1]; console.log('the result is:', result); }else{ console.log('no result'); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.