简体   繁体   English

尝试使用 JS 获取查询字符串参数

[英]Attempting to get Query String Parameters with JS

I'm playing around with a Squarespace Website and attempting to search for/get Query string Parameters.我正在玩 Squarespace 网站并尝试搜索/获取查询字符串参数。 No matter what I try with code injection I get null, of course it works fine in the console but not when I use code injection, it is probably something very simple I'm missing, any help would be appreciated.无论我尝试使用代码注入做什么,我都会得到 null,当然它在控制台中工作正常,但当我使用代码注入时却不行,这可能是我所缺少的非常简单的东西,我们将不胜感激。

www.mysite.com?x=123 www.mysite.com?x=123

(function(){

var urlParams = new URLSearchParams(window.location.search);
console.log(urlParams.get('x')); 

})();

SquareSpace template iFrames in preview version thus it wouldn't work.预览版中的 SquareSpace 模板 iFrame 因此无法使用。 Starting up local live server was my answer.启动本地实时服务器是我的答案。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM