JavaScript;在脚本中调用 src ?
我正在制作一个简单的联属网络营销广告轮换 JavaScript。我对 JavaScript 还很陌生,并不完全理解它,所以请耐心等待。
Google 的 adsense 分为两部分,一部分用于设置变量,另一部分用于获取脚本。然后亚马逊有一个 iframe 来获取它的广告。我想做的就是使用 1 到 2 之间的随机数(稍后会更大),它将随机选择其中一个来显示在我的本地主机上。
<script type="text/javascript"><!--
/* Custom footer */
select = rand(2);
if(select == 1){
google_ad_client = "-----------";
google_ad_slot = "---------";
google_ad_width = ---;
google_ad_height = --;
//get this google
<script ...src="http://pagead2.googlesyndication.com/pagead/show_ads.js
} else {
<iframe src="http://rcm.amazon.com/e/cm?t=------&o=1&p=48&l=ur1&category=amazonhomepage&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
}
</script>
I'm making a simple affiliate ad rotation JavaScript. I'm still new to JavaScript and don't fully understand it so bear with me.
Google's adsense is split into 2 parts, one to set the variables, and the next to get the script. Then Amazon has an iframe to get it's ad's. All I want to do is use a random number from 1 to 2 (will be larger later) that will randomly select one of them to display on my localhost.
<script type="text/javascript"><!--
/* Custom footer */
select = rand(2);
if(select == 1){
google_ad_client = "-----------";
google_ad_slot = "---------";
google_ad_width = ---;
google_ad_height = --;
//get this google
<script ...src="http://pagead2.googlesyndication.com/pagead/show_ads.js
} else {
<iframe src="http://rcm.amazon.com/e/cm?t=------&o=1&p=48&l=ur1&category=amazonhomepage&f=ifr" width="728" height="90" scrolling="no" border="0" marginwidth="0" style="border:none;" frameborder="0"></iframe>
}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用
document.write("or text 将 html 写入页面,但对于 iframe,我建议将其放入另一个 div 中
You need to use
document.write("<html>or text</html")
to write html out to the page, though for the iframe i would suggest putting it inside another div您需要使用
document.write("stringtowritetodocument");
才能让 JavaScript 将任何内容写入文档。因此,在您的
if
内部:此外,一旦复杂性增加,您可能需要注意这一点:
JavaScript的document.write内联脚本执行顺序
你想要的也可能是如果您可以使用一些服务器端代码,则可以更好地完成任务。
You need to use
document.write("stringtowritetodocument");
in order to get JavaScript to write anything to the document.So, inside your
if
:Also, once this grows in complexity, you may need to look out for this:
JavaScript's document.write Inline Script Execution Order
What you want may also be accomplished better with some server-side code, if that is available to you.
您尝试过
Document.Write()
吗?例如
Document.Write("
此处为您的 HTML
Have you tried
Document.Write()
?e.g.
Document.Write("<p>Your HTML Here</p");