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获取值。

更多相关文章

  1. 如何确定在web页面上呈现的字符串的长度(以像素为单位)?
  2. 具有不间断空格的呈现字符串
  3. js字符串与html代码互相转换时怪想法:自己解析js字符串成普通字
  4. iOS:从NSString中删除(一个html字符串)
  5. JQuery查找并更改字符串的样式
  6. 如何截取html的子字符串作为内容摘要
  7. 如果字符串包含html代码,如何用python检测?
  8. html2canvas 识别 svg 解决方案
  9. jquery将html转换为字符串和html

随机推荐

  1. [Android(安卓)学习笔记] 判断 Android(
  2. Android底部弹出iOS7风格对话选项框
  3. 【NFC】Android(安卓)NFC API Reference
  4. Android系统架构——揭开Android系统框架
  5. Android 5.1.1 源码目录结构
  6. Swing中引入Android的NinePatch技术,让Swi
  7. 那些年Android黑科技①:只要活着,就有希望
  8. Android(安卓)IPC
  9. 创业&Android
  10. Android开发者e周报 第6期