I have a script like this
Code:
function resizeCrossDomainIframe(id, other_domain) {
    var iframe = document.getElementById(id);
    window.addEventListener('message', function (event) {
        if (event.origin !== other_domain) return; // only accept messages from the specified domain
        if (event.data === "reload") top.location.reload(); // If child page sends reload request - reload it without any questions asked 
        if (isNaN(event.data)) { //If this isn't integer than it is alert
            alert(event.data); // Show alert if not integer
        } else {
            var height = parseInt(event.data) + 5; // add some extra height to avoid scrollbar
            iframe.height = height + "px";
            alert(event.data);
        }
    }, false);
}
what it does is dynamically resizes iframe. Now On a first iframe page I just get one alert, but in within iframe page i have links and when I go to second page I see 2 alerts, when I go to third page - i get 3 alerts, 4th link trigger 4 alerts etc...

In each iframed page I am calling parent to resize like:
Code:
<body class="settingspage" onload="parent.postMessage(document.body.scrollHeight, '<?php echo $_SESSION['SESS_ACCESSING_FROM']; ?>');">
I tried to clear the "event" array, but I still get Alerts, but this time they are empty, but the number of alerts equals the number of link-clicks within the iframe ?

Why is this and how to limit it only to one "alert"?