I have recreated my problem in the smallest amount of code I could think of Lol
Basically, I have an iFrame that uses addEventListener
using data that the user has posted though a form. It works well, until the user posts again, and then 2 EventListeners are present. I have tried using removeEventListener
but this is not working in this case.
Here is what I have done to recreate the problem:
TESTbuffer.php
<HTML>
<HEAD>
<script>
function startListener() {
parent.document.removeEventListener('mouseup',outputInput,false);
parent.document.addEventListener('mouseup',outputInput,false);
}
function outputInput() {
console.log('<?php echo $_POST['input']; ?>');
}
</script>
</HEAD>
<BODY onload='startListener()'>
</BODY>
</HTML>
TESTparent.php
<iframe name="bufferiframe" id="bufferiframe"></iframe>
<form name="Test" method="POST" action="TESTbuffer.php" target="bufferiframe">
<input type="text" name="input">
<input type="submit" value="Go">
</form>
Here's what happens if you follow these steps:
- Enter 'hello' and click 'Go'
- click anywhere on the screen, then 'hello' appears in the console.
- Enter 'bye' and click 'Go'
- click anywhere on the screen, then 'hello' and 'bye' appears in the console.
I have also tried the function as:
function startListener() {
parent.document.addEventListener('mouseup',outputInput,false);
parent.document.removeEventListener('mouseup',outputInput,false);
parent.document.addEventListener('mouseup',outputInput,false);
}
with the same result
Any help appreciated :D