Pull variable from Query String and add into JS redirect URL

你离开我真会死。 提交于 2019-12-11 23:18:39

问题


I'm trying to get the value of a variable in the query string example.com/?hop=test

And then pass it to a JavaScript in this form:

var exitsplashpage = 'http://example2.com/?hop=original_hop';

How do I get the original hop variable value using JavaScript and what is the correct format to put it into the exitsplashpage var?

Thanks!


回答1:


Try this:

var exitsplashpage = window.location.search.match(/\?hop=([^\&]*)/)[1]



回答2:


Using this getQueryString() function from the link that @Felix Kling posted, you would do the following:

var exitsplashpage = 'http://example2.com/?hop=' + getQueryString()["hop"];

Either that, or have a look at jQuery Query String Object, with which you'd do this:

var exitsplashpage = 'http://example2.com/?hop=' + $.query.get("hop");


来源:https://stackoverflow.com/questions/5657090/pull-variable-from-query-string-and-add-into-js-redirect-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!