[英]Javascript inside of Javascript Popups
I'm using the alert function to create a popup and I was wondering if there was a way to stick script in the popup. 我正在使用警报功能创建弹出窗口,我想知道是否有一种方法可以将脚本粘贴在弹出窗口中。 For example, I want to make a Google ad popup.
例如,我要弹出一个Google广告。 My thoughts for it would be that the popup, instead of displaying text, would display a function.
我的想法是,弹出窗口而不是显示文本,而是显示一个函数。 The function it'd use, 'displayAd()' for example, would just be run in the popup.
它使用的功能(例如“ displayAd()”)将仅在弹出窗口中运行。 Here is my code I'm thinking of.
这是我正在考虑的代码。
<script>
function displayAd()
{
//My Google adsense code
}
function init()//Will occur on page load.
{
alert(displayAd());
}
</script>
I don't believe that'll work, but I'd like input. 我认为这不会奏效,但我想输入意见。 Thanks.
谢谢。
I think it is much easier to simply create a div that will be in the center of the page, with the content of the AD. 我认为,使用AD的内容简单地在页面中心创建一个div会容易得多。
Here I also added a div that will make the whole page fade except the AD. 在这里,我还添加了一个div,它将使除AD之外的整个页面消失。
HTML: HTML:
<body onload="showAD();"> //This will show the AD as soon as the page loads
<div id="fade"> //The fading out of the page div
<div id="AD"> //This div is for your AD
//GOOGLE ADSENSE CODE
</div>
<br>
<button onClick="closeAD();">Close</button> //A button to close the AD
</div>
CSS: CSS:
#fade{
width: 100%:
height: 100%;
background: black;
opacity: 0.7;
text-align: center;
display: none;
}
#AD{
width: #whatever suits you#;
height: #whatever suits you#;
margin-top: 100px;
margin-right: auto;
margin-left: auto;
display: none;
}
Javascript: Javascript:
function displayAD(){
document.getElementById("fade").style.display = block;
document.getElementById("AD").style.display = block;
}
function closeAD(){
document.getElementById("fade").style.display = none;
document.getElementById("AD").style.display = none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.