0

I have two HTML pages. In one of them, we have the JavaScript functions code. In the other one, we want to show the result of the function.

First HTML page:

<script type="text/javascript">
function penAcBoyut(adres, genislik, yukseklik)
{
    var param = "width=" + genislik + "," + "height=" + yukseklik;
    window.open(adres, "_blank", param);
}

function penAcBoyutTest()
{
    penAcBoyut("buton2.html", 400, 300);
}
</script>
<button type="button" onclick="penAcBoyutTest()">Click me</button>

Second HTML page:

<script type="text/javascript">
var clicks = 0;
function penAcBoyutTest() {
    clicks += 1;
    document.getElementById("clicks").innerHTML = clicks;
};
</script>
<p>Clicks: <a id="clicks">0</a></p>

When you click the button on the first page, that open the new page. But the counter doesn't work, doesn't increase the clicks label.

1 Answer 1

1

If you can only get to second page using first page, then execute the function on page load event of second page.

Can use localStorage(preferably) or cookies to store data if needed to pass on.

EDIT: using localStorage:

to set a value.

if(window.localStorage)

    localStorage.setItem('a',1);

and to retrieve:

if(window.localStorage)

  var a =localStorage.getItem('a');
Sign up to request clarification or add additional context in comments.

1 Comment

Could you send me some examples about that. I look for it on google but actually i don't understand how to use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.