我有一个网页需要倒计时器,但倒计时器的 JavaScript 代码是在 iframe
中与其他页面内容一起生成的。我需要使用 Javascript 将此内容推送到父框架中:
document.getElementById('contentarea').innerHTML =
"Please Wait... Countdown is loading FOO";
FOO 的一部分是倒计时代码...
<script>
var upgradeTime = 186000; //no of seconds
var seconds = upgradeTime;
function timer() {
var days = Math.floor(seconds/24/60/60);
}
//The Code doesn't end here but let me not bore anyone
</script>
如何实现此目的,以便注入(inject)的 JavaScript 代码将在父页面上运行?
最佳答案
使用window.parent
在 iframe
的 JavaScript 中。
parent.document.getElementById('contentarea').innerHTML =
"Please Wait... Countdown is loading FOO";
关于javascript - 在父网页的 iframe 中运行 JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37174784/