1

I'm a little bit rusty and just started doing html and javascript again. And need some help with this.

How can I make the information display at a targeted iframe instead of having a new window pop up?

<script LANGUAGE="JavaScript" type="text/javascript">
function display() {
  DispWin = window.open('','NewWin', 'toolbar=no,status=no,width=700,height=400')
  message = "<b>Verified: </b>" + document.form1.Ver.value;
  message += "<br><b>Name: </b>" + document.form1.Gname.value;
  message += "<br><b>ID: </b>" + document.form1.Bid.value;
  message += "<br><b>Concern: </b>" + document.form1.Cxissue.value;
  message += "<br><b>Resolution: </b>" + document.form1.Res.value;
  message += "<br><b>Link: </b>" + document.form1.Htx.value + "<br><br><br>";

  DispWin.document.write(message);
}
    </script>
Pon3_Boy
  • 13
  • 2

1 Answers1

0

You can do it like this:

<iframe id="my-frame"></iframe>
<script>
  var myFrame = document.getElementById('my-frame');
  myFrame.contentDocument.body.innerHTML = 'Hello world!';
</script>

I did not create a StackSnippet because StackOverflow blocks this, but you can see a demo here.

If you really want to use .write(), you can do myFrame.contentDocument.write(...), but it's not used much these days.

blex
  • 22,377
  • 5
  • 35
  • 65
  • I apologize, I guess I wasn't clear enough. Long story short, I'm making a page with multiple iframes, 3 in total, pretty much it's a menu that displays a form that, once completed, I want it to generate a ready to copy/paste request in the 3rd iframe, instead of making a pop-up. Here are the files. https://drive.google.com/open?id=11cETl0f63Jy91r8zNKuQnnMnuVEqUKi3 – Pon3_Boy Mar 14 '20 at 20:33
  • In your form files, replace `DispWin.document.write(message)` with `window.parent.querySelector('iframe[name="Generate"]').contentDocument.body.innerHTML = message;`. It will access the parent page, find the third iframe, and alter its contents. Keep in mind that it won't work if you try it locally with a URL like `file:///C:/....`, you need to serve it with `http(s)`, using a local server or a remote one – blex Mar 14 '20 at 20:41