我找到了一个关于如何使用Javascript创建GUID的示例,但是我如何使用jQuery或Javascript获取当前页面的URL并将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的末尾。我该怎么做呢?
提前感谢
发布于 2013-04-05 23:39:10
使用正则表达式检查该位置是否已有guid,如果没有,则重新加载页面。
var lc = window.location;
if(!(/\?guid=/.test(lc))) {
window.location = window.location + '?guid=' + guid
}https://stackoverflow.com/questions/15837862
复制相似问题