繁体   English   中英

通过window.open将变量传递给新的HTML

[英]pass variable to new HTML with window.open

我从js函数打开html文件:

function initCategoryPage(url){
    var catUrl=url;
    window.open("category.html");
}

我将此脚本放在“ category.html”中,但没有得到var catUrl:

<script>
    myUrl = window.opener.catUrl;
    alert(myUrl)
    id=1;
    firstTime=true;
    ArticlesBlock(); 
</script>

如何将其传递给category.html?

它无法读取的原因是因为该变量不是全局变量。 范围限于该方法。

function initCategoryPage(url){
    window.catUrl=url;  /*make it global*/
    window.open("category.html");
}

更好的解决方案是将其作为查询字符串传递或使用postMessage获取值。

暂无
暂无

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

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