0

The script in the html below works as expected. It loads the latest version of a page by getting today's date info and modifying the iframe src.

But when I put just the script into a WordPress code module for a section of a page, it takes over the whole page. I suspect the problem is the use of document.body.innerHTML, but I don't know what the correct javascript code is.

    <html>
    <head>
    <title>Title</title>
    </head>
    <body>
    <script type="text/javascript">
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
var h = h > 12 ? h - 12 + 'PM' : h + 'AM';
if (dd < 10) {
    dd = '0' + dd;
}
if (mm < 10) {
    mm = '0' + mm;
}
var today = mm + '%2f' + dd + '%2f' + yyyy;
document.body.innerHTML += ' <iframe src="https://www.colorado.gov/airquality/site.aspx?aqsid=080770020&seeddate= ' + today + '" width = "100%" height ="600"> </iframe> ';
</script>

    </body>
    </html>
8
  • 1
    do document.body.innerHTML += Commented Oct 11, 2018 at 17:55
  • This solves the problem of the iframe taking over the whole page. But now the content of the iframe is missing. This can be seen at https://www.citizensforcleanair.org. The iframe is supposed to show the url in the lower right corner. Commented Oct 11, 2018 at 18:09
  • do <iframe src="https://www.colorado.gov/airquality/site.aspx?aqsid=080770020&seeddate= '+today+'" width = "100%" height ="600"> </iframe> instead. Commented Oct 11, 2018 at 18:36
  • This helps, but I'm still not seeing the url in the lower right corner of the page. See citizensforcleanair.org. The javascript console reports a syntax error Unexpected token < Commented Oct 11, 2018 at 18:55
  • 1
    do this then document.getElementsByClassName('et_pb_code_inner')[1].innerHTML += ' <iframe src="https://www.colorado.gov/airquality/site.aspx?aqsid=080770020&seeddate= ' + today + '" width = "100%" height ="600"> </iframe> '; Commented Oct 11, 2018 at 20:17

1 Answer 1

1
document.getElementsByClassName('et_pb_code_inner')[1].innerHTML += ' <iframe src="https://www.colorado.gov/airquality/site.aspx?aqsid=080770020&seeddate= ' + today + '" width = "100%" height ="600"> </iframe> ';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.