StarLiike
StarLiike

Reputation: 13

How can I fix the problem with the iframe when reloading the page in firefox?

if I enter something in the textarea and reload the page, my code is then output again in the iFrame. However, the problem only occurs in Firefox.

<div id="html-area"> </div>
<textarea id="html-editor" placeholder="HTML" oninput="changer()"></textarea>
<iframe id="viewer"></iframe>

<script>
function changer(){
var htmlcode = document.getElementById("html-editor").value;

viewfield = document.getElementById("viewer").contentWindow.document;

viewfield.open();
viewfield.write(htmlcode);
viewfield.close();
}
</script>

Can someone tell me how to work around the problem in Firefox? If there is already a similar thread, I'm sorry, couldn't find anything.

Thank you in advance for the help

Upvotes: 1

Views: 336

Answers (1)

alessandrio
alessandrio

Reputation: 4370

firefox has the autocomplete value by default on
you should turn it off if you don't need to retrieve the data on refresh.

<textarea ... autocomplete="off">

when you use document.write to modify iframe content, an automatic entry is added to the session history for each use. so you should clean it at the beginning.

viewfield = document.getElementById("viewer").contentWindow.document;
viewfield.write('');

function changer() {
  var htmlcode = document.getElementById("html-editor").value;
  viewfield.open();
  viewfield.write(htmlcode);
  viewfield.close();
}

Upvotes: 1

Related Questions