javascript 如何在javascript中刷新div,它有另一个脚本作为主体?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16943161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 06:33:54  来源:igfitidea点击:

How to refresh div in javascript, which has another script as body?

javascriptads

提问by Fahim Akhter

I was using an advertising service (banner) which had a simple refresh timer in it. Where I could specify after what time the advert should be reloaded (or a new one should be served)

我正在使用一个广告服务(横幅),其中有一个简单的刷新计时器。我可以在哪里指定应该重新加载广告的时间(或应该提供新的广告)

I've switched my banner provider and the new one does not have that built in option.

我已经更换了我的横幅提供商,而新的没有内置选项。

I've tried refreshing the div normally but that doesn't work since the content seems to remain the same.

我试过正常刷新 div 但这不起作用,因为内容似乎保持不变。

Any ideas on a javascript code which can refresh a banner ad?

关于可以刷新横幅广告的 javascript 代码的任何想法?

<script langauge="javascript">  
window.setInterval("refreshDiv()", 60000);  
function refreshDiv(){  
    document.getElementById("advert_div").innerHTML;
}
</script>

and here is the advertisers div

这是广告商 div

<div id="advert_div">
        <script type="text/javascript">
            //<![CDATA[
                LSM_Slot({
                    adkey: '645451',
                    ad_size: '300x250',
                    slot: 'slot656464'
                });
            //]]>
        </script>
    </div>

回答by Mirko Cianfarani

I say my idea or suggest. I had one situation but there was the script with document.write()and this is not that you used. Info: my answer(I was writing before the update's question)

我说我的想法或建议。我有一种情况,但有脚本,document.write()这不是你使用的。信息:我的回答(我是在更新问题之前写的)

2. ideaIn your case

2.idea在你的情况下

  <script language="javascript">  
    window.setInterval("refreshDiv()", 60000);  
    function refreshDiv(){  
        document.getElementById("advert_div").innerHTML;
    }
    </script>

The document.getElementById("advert_div").innerHTMLmiss =as what?

document.getElementById("advert_div").innerHTML小姐=是什么?

Example

例子

document.getElementById("advert_div").innerHTML="<p>Welcome</p>"

EDIT:

编辑:

You can create the element with

您可以创建元素

document.getElementById("advert_div").innerHTML="";
         var src1 = 'script',
                script1 = document.createElement('SCRIPT');
                script1.type="text/javascript";
           script1.src = src1;
           document.getElementById("advert_div").appendChild(script1);

This is a banal example but you can create the function in every banner and create the function:

这是一个平庸的例子,但您可以在每个横幅中创建函数并创建函数:

"use strict";
var name = "foo";
var func = new Function(
     "return function " + name + "(){ alert('sweet!')}"
)();

//call it, to test it
func();

Info:

信息:

function refreshDiv(){  

            document.getElementById("advert_div").innerHTML="";
            //Calling the function using the if
        }

Now I do not know exactly what you want to do and I writing my ideas. Good luck and if you seek help.

现在我不知道你到底想做什么,我写我的想法。祝你好运,如果你寻求帮助。