[英]Add query string or GUiD to the end of URL on page load using Javascript
我找到了一个有关如何使用Javascript创建GUID的示例,但是如何获取当前页面URL并使用jQuery或Javascript将GUID附加到它。
function S4() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
// then to call it, plus stitch in '4' in the third group
guid = (S4() + S4() + "-" + S4() + "-4" + S4().substr(0, 3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
//alert(guid);
我尝试了window.location = window.location +'?guid ='+ guid,但这只是一遍又一遍地重定向页面,同时将guid附加到URL的末尾。
一旦页面加载,我只需要将GUID附加到URL的末尾。 我该怎么做?
提前致谢
使用正则表达式检查该位置是否已经有GUID,如果不存在,请重新加载页面。
var lc = window.location;
if(!(/\?guid=/.test(lc))) {
window.location = window.location + '?guid=' + guid
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.