In this blog, I am not going to talk about anything about C#, ASP.NET or any of the technical or architectural stuffs. This is actually a post for my refreshment. Recently I have added a new feature to my blog to ensure that the users who visits my site for the first time gets a warm welcome message telling about the features of the site. Lets show you how to do that, so that others who are using the same to blog their content can benefit from it.
The Funda
Here are the steps to do :
- Add a small div element to the blogger template which contains the message.
- Add a css for the div to ensure the message is hidden.
- Try to find a cookie through javascript after the page loads.
- If cookie is found, we do nothing, otherwise we unhide the message and store the cookie in the browser.
The steps
In blogger's console, click on Design. Next go to Edit Template.
Try to find
tag.
After body tag place the following html :
<div id='layer1'> <p>Welcome to my site. Thanks for visiting.(Dismiss)</a></p> </div>
Now move up, and before end of head place a script block :
<script type='text/javascript'> function GetCookie(name) { var arg=name+"="; var alen=arg.length; var clen=document.cookie.length; var i=0; while (i<clen) { var j=i+alen; if (document.cookie.substring(i,j)==arg) return "here"; i=document.cookie.indexOf(" ",i)+1; if (i==0) break; } return null; } function setVisible(obj,isopen) { obj = document.getElementById(obj); obj.style.visibility = !isopen ? "hidden" : "visible"; } function placeIt(obj) { obj = document.getElementById(obj); if (document.documentElement) { theLeft = document.documentElement.scrollLeft; theTop = document.documentElement.scrollTop; } else if (document.body) { theLeft = document.body.scrollLeft; theTop = document.body.scrollTop; } theLeft += x; theTop += y; obj.style.left = theLeft + 'px' ; obj.style.top = theTop + 'px' ; setTimeout("placeIt('layer1')",500); } function loadFirstTime(){ x = 0; y = 0; var visit=GetCookie("COOKIE1"); if (visit==null){ var expire=new Date(); window.name = "thiswin"; setVisible('layer1', true); expire=new Date(expire.getTime()+7776000000); document.cookie="COOKIE1=here; expires="+expire; } window.onscroll = function(){ placeIt('layer1'); } } <script>
Replace the body tag with
Thus the body tag calls loadFirstTime when the page loads up.
Finally in the style section add
#layer1 { position: absolute; visibility: hidden; width: 100%; height: 60px; left: 0px; top: 0px; color:#FFF; background-color: #AF7817; border: 1px solid #000; padding: 0px; }
Now when you visit the site after deleting the browser cookie, you will see the welcome message. Try clicking on dismiss to dismiss the message.
Thank you for reading the content.
your guide is not a user friendly!
ReplyDeleterevise
Hi - I am really happy to find this. cool job!
ReplyDelete