简体   繁体   English

如何通过HTML中的查询字符串更改URL重定向

[英]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'); } 
this one of the solultion, i think you shouldn't forget myUrl.includes to prevent undefined value; 这是一种解决方案,我认为您不应忘记myUrl.includes以防止未定义的值;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将查询字符串添加到URL重定向 - Add query string to URL redirect 如何基于Url中的查询字符串以编程方式更改Url - How to programmatically change the Url based on a query string in Url JavaScript:使用HiddenField中的查询字符串重定向到URL - JavaScript: Redirect to a URL with query string in HiddenField 使用Javascript重定向到带有查询字符串的URL时出现问题 - Problem using Javascript to redirect to a URL with a query string 如何将 HTML 表单数据作为路径而不是作为查询字符串附加到 URL 中? - How to append HTML form data into the URL as path and not as a query string? 如何将函数绑定到URL查询字符串的更改,而不是hashchange - How to bind a function to change of URL query string, NOT to hashchange 如何将FlashVars参数更改为URL查询字符串? - How can I change FlashVars parameters into a URL query string? 如何从URL重定向中删除查询字符串 - How do I remove the query-string from my URL redirect 如何从动态表单中获取值,将其传递给变量并使用JavaScript中的查询字符串参数重定向到URL? - How to get values from dynamic form, pass them to a variable and redirect to a URL with query string parameters in JavaScript? 更改下拉列表后,如何重定向到另一个网址 - On change of dropdown how will I redirect to another URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM