使用window.open将变量传递给新的HTML
16lz
2021-01-22
Im opening html file from js function:
我从js函数打开html文件:
function initCategoryPage(url){
var catUrl=url;
window.open("category.html");
}
I putted this script in "category.html" but it doesnt get the var catUrl:
我把这个脚本放在“category.html”中,但它没有得到var catUrl:
<script>
myUrl = window.opener.catUrl;
alert(myUrl)
id=1;
firstTime=true;
ArticlesBlock();
</script>
how can I pass it to category.html?
我怎样才能将它传递给category.html?
1 个解决方案
#1
2
The reason it can not read it is because the variable is not global. The scope is limited to that method.
它无法读取它的原因是因为变量不是全局变量。范围仅限于该方法。
function initCategoryPage(url){
window.catUrl=url; /*make it global*/
window.open("category.html");
}
A better solution would be to pass it as a querystring or use postMessage to get the value.
更好的解决方案是将其作为查询字符串传递或使用postMessage获取值。
更多相关文章
- 如何确定在web页面上呈现的字符串的长度(以像素为单位)?
- 具有不间断空格的呈现字符串
- js字符串与html代码互相转换时怪想法:自己解析js字符串成普通字
- iOS:从NSString中删除(一个html字符串)
- JQuery查找并更改字符串的样式
- 如何截取html的子字符串作为内容摘要
- 如果字符串包含html代码,如何用python检测?
- html2canvas 识别 svg 解决方案
- jquery将html转换为字符串和html