yoram
yoram

Reputation: 201

pass variable to new HTML with window.open

Im opening html file from js function:

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

I putted this script in "category.html" but it doesnt get the var catUrl:

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

how can I pass it to category.html?

Upvotes: 0

Views: 1389

Answers (1)

epascarello
epascarello

Reputation: 207557

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.

Upvotes: 2

Related Questions