0

Well, to put it simply, this doesn't work:

<script>
alert("You are about to send email to the client! Do you want to proceed?");
var frame = document.getElementById("iframeMailer");
frame.src="qr.php";
</script>

When the user presses okay, the source of the iframe does not load.

It is by the way defined as follows:

<iframe src="example.php" height=130 width=50% frameBorder="0" seamless name="iframeMailer" id="iframeMailer"></iframe>
7segment
  • 33
  • 6
  • Probably a ducplicate of: https://stackoverflow.com/questions/3730159/changing-iframe-src-with-javascript – MetallimaX Dec 10 '20 at 17:02
  • http://jsfiddle.net/mjcLozdw/1/ - works for me – James Paterson Dec 10 '20 at 17:05
  • Is your javascript at the top or bottom of the page? I would try putting it below the iframe in case the problem is on load the iframe has loaded yet but the javascript is already referencing it. – imvain2 Dec 10 '20 at 17:09
  • Does this answer your question? [why is simple javascript code not running?](https://stackoverflow.com/questions/6092172/why-is-simple-javascript-code-not-running) – Heretic Monkey Dec 10 '20 at 17:31

2 Answers2

0

You must put javascript before tag "body"

<script>
alert("You are about to send email to the client! Do you want to proceed?");
var frame = document.getElementById("iframeMailer");
frame.src="qr.php";
</script>
</body>
Mark
  • 74
  • 3
0

First of all, Use confirm instead of alert because alert cannot receive input from the user. Your code should be something like

<script>
    function queryFrame () {
        var frame = document.getElementById("iframeMailer");
        if (confirm("You are about to send email to the client! Do you want to proceed?")) {        
            frame.src="qr.php";
        }
    }

    window.addEventListener("DOMContentLoaded", queryFrame())
</script>

And the HTML:

<iframe height=130 width=50% frameBorder="0" seamless name="iframeMailer" id="iframeMailer"></iframe>
Elpis
  • 79
  • 6