[英]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.