每10分钟显示一次插页式广告

时间:2016-12-20 23:23:14

标签: javascript jquery html css

我最近一直在努力处理广告及其频次上限。 我使用Adform(一个广告平台)并且我已经被要求为移动访问者创建插页式广告,其方式应该每X分钟只显示一次。 (每次在网站上阅读其他帖子时都会收到插页式广告很烦人。)

到目前为止,我一直在使用预制脚本,它可以正常使用img和table标签,但不能使用脚本本身! 这是迄今为止使用的脚本:



<html>

<head>
<script type="text/javascript">

/***********************************************
* Frequency Cap Content script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Please keep this notice intact
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

//["ID of content to frequency cap", "Display frequency interval (full hours only)"]
var capcontent=new Array()
capcontent[0]=["myad", "1 hr"]
capcontent[1]=["mynote", "3 hr"]

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function resetcookie(id){
var expireDate = new Date()
expireDate.setHours(expireDate.getHours()-10)
document.cookie = id+"=;path=/;expires=" + expireDate.toGMTString()
}

function showorhide(caparray){
if (get_cookie(caparray[0])!='')
document.write("#"+caparray[0]+"{display: none;}\n") //CSS TO HIDE CONTENT BTW FREQUENCY
else{
var expireDate = new Date()
expireDate.setHours(expireDate.getHours()+parseInt(caparray[1]))
document.cookie = caparray[0]+"="+parseInt(caparray[1])+";path=/;expires=" + expireDate.toGMTString()
}
}

document.write('<style type="text/css">\n')

for (i=0; i<capcontent.length; i++){
if (get_cookie(capcontent[i][0])!=parseInt(capcontent[i][1]))
resetcookie(capcontent[i][0])
showorhide(capcontent[i])
}

document.write('</style>')

</script>
</head>

<body>

<div id="myad">

<script type="text/javascript" src="http://adx.adform.net/adx/?mid=303469&rnd=%%ADFRND%%"></script>


</div>

<div id="table">

</table>

</body>
</html>
&#13;
&#13;
&#13;

正如您可能已经注意到的那样,在ID为#34; myad&#34;我已经插入了javascript代码。如果我打开网站,广告会显示,但一旦关闭并重新加载页面,它就会一直显示出来!

请帮忙吗?

1 个答案:

答案 0 :(得分:0)

我希望你能使用这段代码:

    function showInterstitial() {
    if ($.cookie("IntersCookie") == null) {
        $.cookie("IntersCookie", "1", {
            path: ".mydomain.com",
            expires: 1
        });

    }
}

试试吧!