jquery幻灯片切换iframe覆盖隐藏或显示
我有一段代码,根据用户是否单击按钮隐藏/显示div。它还设置了一个cookie来记住状态,因此如果用户刷新页面,div状态保持不变。一切都很正常,直到我添加代码来显示DFP广告,并且由于某种原因,当页面刷新时,它使用的iframe覆盖了隐藏状态——它仍然显示广告,即使包含的div是隐藏的 这是我的代码,如果您能帮我整理一下,我将不胜感激:-) 谢谢 就现在这样jquery幻灯片切换iframe覆盖隐藏或显示,jquery,slidetoggle,google-dfp,Jquery,Slidetoggle,Google Dfp,我有一段代码,根据用户是否单击按钮隐藏/显示div。它还设置了一个cookie来记住状态,因此如果用户刷新页面,div状态保持不变。一切都很正常,直到我添加代码来显示DFP广告,并且由于某种原因,当页面刷新时,它使用的iframe覆盖了隐藏状态——它仍然显示广告,即使包含的div是隐藏的 这是我的代码,如果您能帮我整理一下,我将不胜感激:-) 谢谢 就现在这样 #广告牌按钮{ 背景色:#f1f1; 颜色:#666; 填充:3倍; 宽度:100px; 光标:指针; 文本对齐:居中; 保证金:0自
#广告牌按钮{
背景色:#f1f1;
颜色:#666;
填充:3倍;
宽度:100px;
光标:指针;
文本对齐:居中;
保证金:0自动;
}
var googletag=googletag | |{};
googletag.cmd=googletag.cmd | |[];
(功能(){
var gads=document.createElement('script');
gads.async=true;
gads.type='text/javascript';
var usesssl='https:'==document.location.protocol;
gads.src=(使用SSL?'https:':'http:')+
“//www.googletagservices.com/tag/js/gpt.js”;
var node=document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads,节点);
})();
googletag.cmd.push(函数(){
googletag.defineSlot('/4856165/Forum_Billboard_970x250',[970250],'Billboard').addService(googletag.pubads());
googletag.pubads().setTargeting('SiteType','giraffetest');
googletag.enableServices();
});
$(文档).ready(函数(){
//检查是否已设置公告牌状态cookie
如果($.cookie('billboardStatus')){
//如果是,请定义变量
var cook=$.cookie('billboardStatus');
}否则{
//否则,默认情况下将其设置为true,到期日期为1天=24小时
var cook=$.cookie('billboardStatus','true',{expires:1});
}
//刷新时,如果cookie值为false,即广告点关闭
如果(cook=='false'){
//隐藏广告牌广告点
$(“#公告牌”).hide();
//更改打开/关闭按钮设置
$(“#billboardButton”).css(“backgroundColor”,“#e1e1e1”).text(“打开的广告”);
}else{//else如果该值设置为true,即打开
//展示广告点
$('广告牌').show();
//更改打开/关闭按钮设置
$(“#billboardButton”).text(‘关闭广告’);
}
//当用户点击打开/关闭按钮时…
$(“#billboardButton”)。在('单击',函数()上{
//切换广告点的打开/关闭
$(“#公告牌”).stop().slideToggle('slow',function()){
//根据按钮当前处于的状态,设置按钮的背景颜色和文本值
$(“#billboardButton”).css(“backgroundColor”,$(this).is(':not(:visible)?“#e1e1e1e1:”).text($(this).is(':visible')?“Close Ad':“Open Ad”);
//将cookie值设置为false,即关闭
$.cookie('billboardStatus',$(this).is(':visible'),{expires:1});
});//结束滑动切换
});//单击结束
}); // 结束文件准备就绪
关闭广告
//googletag.cmd.push(函数(){googletag.display('billboard');});
通过jQuery而不是直接在html中添加dfp代码,找到了答案。我们已经将调用代码分为两行(59和73),并对其进行了测试。这是完成的代码
<style>
#billboardButton {
background-color:#f1f1f1;
color:#666;
padding:3px;
width:100px;
cursor:pointer;
text-align:center;
margin:0 auto;
}
</style>
<!-- Load the latest version of jQuery -->
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<!-- Load the jquery.cookie.js plugin -->
<script src="https://googledrive.com/host/0B7ZDS1Dob8_8WXhpUVdtNjVNdWc/"></script>
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/4856165/Forum_Billboard_970x250', [970, 250], 'billboard').addService(googletag.pubads());
googletag.pubads().setTargeting('SiteType', 'giraffetest');
googletag.enableServices();
});
</script>
<script>
$(document).ready(function(){
// Check to see if the billboardStatus cookie has been set
if($.cookie('billboardStatus')) {
// If yes, define the variable
var cook = $.cookie('billboardStatus');
} else {
// Else set it as true by default and with an expiry date of 1 day = 24 hours
var cook = $.cookie('billboardStatus', 'true', {expires: 1});
}
// On refresh, if the cookie value is false i.e. the ad spot is closed
if(cook=='false') {
// hide the billboard ad spot
$('#billboard').hide();
//$('iframe,#google_ads_iframe_/4856165/Forum_Billboard_970x250_0').css('display','none');
// Change the open/close button settings
$("#billboardButton").css("backgroundColor", "#e1e1e1").text('Open Ad');
} else { // Else if the value is set as true i.e. open
// Show the ad spot
$('#billboard').show().html("<script type='text/javascript'>googletag.cmd.push(function() { googletag.display('billboard'); });<\/script>");
// Change the open/close button settings
$("#billboardButton").text('Close Ad');
}
// When the user clicks on the open/close button…
$('#billboardButton').on('click', function() {
// Toggle the opening/closing of the ad spot
$('#billboard').stop().slideToggle('slow', function(){
// Set the background colour and the text value of the button depending on what state the button is currently in
$("#billboardButton").css("backgroundColor", $(this).is(':not(:visible)') ? "#e1e1e1" : "").text($(this).is(':visible') ? 'Close Ad' : 'Open Ad');
// Set the cookie value to false i.e. closed
$.cookie('billboardStatus', $(this).is(':visible'), {expires:1});
$("#billboard").is(':visible') ? $("#billboard").html("<script type='text/javascript'>googletag.cmd.push(function() { googletag.display('billboard'); });<\/script>") : "";
}); // End slideToggle
return false;
}); // End on click
}); // End document ready
</script>
<div style="width:970px;margin:20px auto;">
<div id="billboardButton">Close Ad</div>
<div id='billboard' style='width:970px; height:250px; background-color:#0C9;'></div>
</div>
#广告牌按钮{
背景色:#f1f1;
颜色:#666;
填充:3倍;
宽度:100px;
光标:指针;
文本对齐:居中;
保证金:0自动;
}
var googletag=googletag | |{};
googletag.cmd=googletag.cmd | |[];
(功能(){
var gads=document.createElement('script');
gads.async=true;
gads.type='text/javascript';
var usesssl='https:'==document.location.protocol;
gads.src=(使用SSL?'https:':'http:')+
“//www.googletagservices.com/tag/js/gpt.js”;
var node=document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads,节点);
})();
googletag.cmd.push(函数(){
googletag.defineSlot('/4856165/Forum_Billboard_970x250',[970250],'Billboard').addService(googletag.pubads());
googletag.pubads().setTargeting('SiteType','giraffetest');
googletag.enableServices();
});
$(文档).ready(函数(){
//检查是否已设置公告牌状态cookie
如果($.cookie('billboardStatus')){
//如果是,请定义变量
var cook=$.cookie('billboardStatus');
}否则{
//否则,默认情况下将其设置为true,到期日期为1天=24小时
var cook=$.cookie('billboardStatus','true',{expires:1});
}
//刷新时,如果cookie值为false,即广告点关闭
如果(cook=='false'){
//隐藏广告牌广告点
$(“#公告牌”).hide();
//$(“iframe,#谷歌广告(iframe)/4856165/论坛(bulleboard)css('display','none');
//更改打开/关闭按钮设置
$(“#billboardButton”).css(“backgroundColor”,“#e1e1e1”).text(“打开的广告”);
}else{//else如果该值设置为true,即打开
//展示广告点
$(#billboard').show().html(“googletag.cmd.push(function(){googletag.display('billboard');}”);
//更改打开/关闭按钮设置
$(“#billboardButton”).text(‘关闭广告’);
}
//当用户单击打开/关闭按钮时…
$(“#billboardButton”)。在('单击',函数()上{
//切换广告点的打开/关闭
$(“#公告牌”).stop().slideToggle('slow',function()){
//根据按钮当前处于的状态,设置按钮的背景颜色和文本值
$(“#billboardButton”).css(“backgroundColor”,$(this).is(':not(:visible)?“#e1e1e1e1:”).text($(this).is(':visible')?“Close Ad':“Open Ad”);
//将cookie值设置为false,即关闭
<style>
#billboardButton {
background-color:#f1f1f1;
color:#666;
padding:3px;
width:100px;
cursor:pointer;
text-align:center;
margin:0 auto;
}
</style>
<!-- Load the latest version of jQuery -->
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<!-- Load the jquery.cookie.js plugin -->
<script src="https://googledrive.com/host/0B7ZDS1Dob8_8WXhpUVdtNjVNdWc/"></script>
<script type='text/javascript'>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
</script>
<script type='text/javascript'>
googletag.cmd.push(function() {
googletag.defineSlot('/4856165/Forum_Billboard_970x250', [970, 250], 'billboard').addService(googletag.pubads());
googletag.pubads().setTargeting('SiteType', 'giraffetest');
googletag.enableServices();
});
</script>
<script>
$(document).ready(function(){
// Check to see if the billboardStatus cookie has been set
if($.cookie('billboardStatus')) {
// If yes, define the variable
var cook = $.cookie('billboardStatus');
} else {
// Else set it as true by default and with an expiry date of 1 day = 24 hours
var cook = $.cookie('billboardStatus', 'true', {expires: 1});
}
// On refresh, if the cookie value is false i.e. the ad spot is closed
if(cook=='false') {
// hide the billboard ad spot
$('#billboard').hide();
//$('iframe,#google_ads_iframe_/4856165/Forum_Billboard_970x250_0').css('display','none');
// Change the open/close button settings
$("#billboardButton").css("backgroundColor", "#e1e1e1").text('Open Ad');
} else { // Else if the value is set as true i.e. open
// Show the ad spot
$('#billboard').show().html("<script type='text/javascript'>googletag.cmd.push(function() { googletag.display('billboard'); });<\/script>");
// Change the open/close button settings
$("#billboardButton").text('Close Ad');
}
// When the user clicks on the open/close button…
$('#billboardButton').on('click', function() {
// Toggle the opening/closing of the ad spot
$('#billboard').stop().slideToggle('slow', function(){
// Set the background colour and the text value of the button depending on what state the button is currently in
$("#billboardButton").css("backgroundColor", $(this).is(':not(:visible)') ? "#e1e1e1" : "").text($(this).is(':visible') ? 'Close Ad' : 'Open Ad');
// Set the cookie value to false i.e. closed
$.cookie('billboardStatus', $(this).is(':visible'), {expires:1});
$("#billboard").is(':visible') ? $("#billboard").html("<script type='text/javascript'>googletag.cmd.push(function() { googletag.display('billboard'); });<\/script>") : "";
}); // End slideToggle
return false;
}); // End on click
}); // End document ready
</script>
<div style="width:970px;margin:20px auto;">
<div id="billboardButton">Close Ad</div>
<div id='billboard' style='width:970px; height:250px; background-color:#0C9;'></div>
</div>
onClick="funtionName()"
funtion funtionName(){
$('#iframeID').toggle();
}