Jump to content

how to show ads for only first visit


flori21

Recommended Posts

please help me i am a code for ads and i want to be shown only on the first 2 visits to the website my javascript code : <!-- Improve e3lan --><style type="text/css">#topbar{position:absolute;border: 1px solid black;padding: 4px;background-color: white;width: 120px;visibility: hidden;z-index: 0;}</style><script type="text/javascript">var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser sessionvar startX = 30 //set x offset of bar in pixelsvar startY = 4 //set y offset of bar in pixelsvar verticalpos="fromtop" //enter "fromtop" or "frombottom"function iecompattest(){return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body}function get_cookie(Name) {var search = Name + "="var returnvalue = "";if (document.cookie.length > 0) {offset = document.cookie.indexOf(search)if (offset != -1) {offset += search.lengthend = document.cookie.indexOf(";", offset);if (end == -1) end = document.cookie.length;returnvalue=unescape(document.cookie.substring(offset, end))}}return returnvalue;}function closebar(){if (persistclose)document.cookie="remainclosed=1"document.getElementById("topbar").style.visibility="hidden"}function staticbar(){barheight=document.getElementById("topbar").offsetHeightvar ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;var d = document;function ml(id){var el=d.getElementById(id);if (!persistclose || persistclose && get_cookie("remainclosed")=="")el.style.visibility="visible"if(d.layers)el.style=el;el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};el.x = startX;if (verticalpos=="fromtop")el.y = startY;else{el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;el.y -= startY;}return el;}window.stayTopLeft=function(){if (verticalpos=="fromtop"){var pY = ns ? pageYOffset : iecompattest().scrollTop;ftlObj.y += (pY + startY - ftlObj.y)/8;}else{var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;ftlObj.y += (pY - startY - ftlObj.y)/8;}ftlObj.sP(ftlObj.x, ftlObj.y);setTimeout("stayTopLeft()", 10);}ftlObj = ml("topbar");stayTopLeft();}if (window.addEventListener)window.addEventListener("load", staticbar, false)else if (window.attachEvent)window.attachEvent("onload", staticbar)else if (document.getElementById)window.onload=staticbar</script> <div id="topbar"><a href="" onClick="closebar(); return false"><img src="close.gif" border="0" /></a><a href="http://www.egsite.com/games/file.php?f=91"><img src="http://www.egsite.com/vb/images/boush.gif"></a> </div><www.egsite.com/vb><!-- End e3lan -->

Link to comment
Share on other sites

thank you very much for answeri link my adsfunction checkCookie(){CookieValue=getCookie('#topbar');if(CookieValue=='')#topbarsetCookie('#topbar',VBname,365);}but nothing do ,still show ads every time my page loadwhere is the Mistake ?

Link to comment
Share on other sites

the examle in site w3school for show a alert with text inside butin my case i dont want show alert with text and only ads so i made a some change and this is all my code<!DOCTYPE html><html><head><script>function getCookie(c_name){if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1){ c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } }return "";}function setCookie(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());}function checkCookie(){CookieValue=getCookie('#topbar');if(CookieValue=='')#topbarsetCookie('#topbar','#topbar',365);}</script></head><body onload="checkCookie()"></body></html>but nothing do ,still show ads every time my page loadplease tell me where is the Mistake ?

Link to comment
Share on other sites

Ads? I don't see any ads being displayed in your code. Please create the simplest COMPLETE script you can that just displays something easy based on a JS cookie and post it.Also, it will help you if your script has comments.

Edited by niche
Link to comment
Share on other sites

ok ,i will post all my code <!-- Improve ads --><!DOCTYPE html><html><head><style type="text/css">#topbar{position:absolute;border: 1px solid black;padding: 4px;background-color: white;width: 120px;visibility: hidden;z-index: 0;}</style> <script type="text/javascript">var persistclose=0 //set to 0 or 1. 1 means once the bar is manually closed, it will remain closed for browser sessionvar startX = 30 //set x offset of bar in pixelsvar startY = 4 //set y offset of bar in pixelsvar verticalpos="fromtop" //enter "fromtop" or "frombottom"function iecompattest(){return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body}function get_cookie(Name) {var search = Name + "="var returnvalue = "";if (document.cookie.length > 0) {offset = document.cookie.indexOf(search)if (offset != -1) {offset += search.lengthend = document.cookie.indexOf(";", offset);if (end == -1) end = document.cookie.length;returnvalue=unescape(document.cookie.substring(offset, end))}}return returnvalue;}function closebar(){if (persistclose)document.cookie="remainclosed=0"document.getElementById("topbar").style.visibility="hidden"}function staticbar(){barheight=document.getElementById("topbar").offsetHeightvar ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;var d = document;function ml(id){var el=d.getElementById(id);if (!persistclose || persistclose && get_cookie("remainclosed")=="")el.style.visibility="visible"if(d.layers)el.style=el;el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};el.x = startX;if (verticalpos=="fromtop")el.y = startY;else{el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;el.y -= startY;}return el;}window.stayTopLeft=function(){if (verticalpos=="fromtop"){var pY = ns ? pageYOffset : iecompattest().scrollTop;ftlObj.y += (pY + startY - ftlObj.y)/8;}else{var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;ftlObj.y += (pY - startY - ftlObj.y)/8;}ftlObj.sP(ftlObj.x, ftlObj.y);setTimeout("stayTopLeft()", 10);}ftlObj = ml("topbar");stayTopLeft();}if (window.addEventListener)window.addEventListener("load", staticbar, false)else if (window.attachEvent)window.attachEvent("onload", staticbar)else if (document.getElementById)window.onload=staticbar</script><script type="text/javascript" src="firstvisit.js"></script><script type="text/javascript">$(document).ready(function(){ if ($.cookie("hide") != "true") { $(".div").hide() ; $(".div").delay(2000).fadeIn(6000); $.cookie("hide", "true") } });</script> </head><body><div id="topbar"><a href="" onClick="closebar();return false "><img src="/close.gif" border="0" /></a><a href="http://www.egsite.com/games/file.php?f=91"><img src="http://www.egsite.com/vb/images/boush.gif"></a></div><body onload="checkCookie()"></body></body></html><!-- End ads--> and i upload a "firstvisit.js" to the root of my site the code of "firstvisit.js" is <!DOCTYPE html><html><head><script>function getCookie(c_name){if (document.cookie.length>0) {c_start=document.cookie.indexOf(c_name + "=");if (c_start!=-1){c_start=c_start + c_name.length+1;c_end=document.cookie.indexOf(";",c_start);if (c_end==-1) c_end=document.cookie.length;return unescape(document.cookie.substring(c_start,c_end));}}return "";} function setCookie(c_name,value,expiredays){var exdate=new Date();exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());}function checkCookie(){CookieValue=getCookie('#topbar');if(CookieValue=='')#topbarsetCookie('#topbar','#topbar',365); }</script></head><body onload="checkCookie()"></body></html>

Edited by flori21
Link to comment
Share on other sites

That's why a suggested a simple script. I will be easier for us to discuss. For example, all you've said is that it doesn't work. What are your developer tools telling you and which values have you checked? Answers to these question will be easier to demo on a more basic script that targets your questions.

Link to comment
Share on other sites

ok .i think here is a problem ,doesnt work ,div= topbar }function checkCookie(){CookieValue=getCookie('#topbar');if(CookieValue=='')#topbarsetCookie('#topbar','#topbar',365); }

Edited by flori21
Link to comment
Share on other sites

That should make you feel good to be able to DIY! Nobody likes to be too dependent.

Edited by niche
Link to comment
Share on other sites

i dont understand , i dont know english very wel ,i translated from english to romanian by google and i dont understandAsta ar trebui să te simți mai bine să fie în măsură să DIY!DIY=?NO sir i dont want to be dependent believe me, but i tryed much ,and nothing happenmay be i do MistakeI will try more and tell you the result

Edited by flori21
Link to comment
Share on other sites

DIY = Do It Yourself. That's the goal of all forums: that the poster will learn to do it themself.

Edited by niche
Link to comment
Share on other sites

Writing "#topbar" is not valid Javascript, that's an error. That doesn't mean anything to Javascript. You showed a .js file that had HTML code in it, HTML code does not go in Javascript files. That's another error. You should be using your browser's developer tools to help you when you're developing this, the developer console will show any error messages from Javascript like the ones I mentioned. There are links in my signature that describe the developer tools in each browser.

Link to comment
Share on other sites

thank you very much sir for information you are right and i solved this problemthe Solution is putting div# topbar { /* Hide the div */ display: none;} betwen tag <style type="text/css"> and </style>and putting javascripe code :<script type="text/javascript">var cookie = document.cookie;if (cookie.indexOf('visited=', 0) == -1) { var expiration = new Date(); expiration.setDate(expiration.getDate()+1); document.cookie = 'visited=1;expires=' + expiration + ';path=/'; var element = document.getElementById('topbar'); element.style.display = 'block';}</script> betwen tag <body> and </body> and i am very happy for that matter thank you very much

Edited by flori21
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...