Popup Window
Popup windows are browser windows opened from a web page and used most of times for displaying advertisements.
The popup below activated when the user clicks on a link.
The time between two instances is 24 hours, you can change that if in the function “showPopupWindow” change the number that represents the hours of the cookie expiration (24 in this case).
In the same function replace the “www.example.com” with the url you want to display in the popup window.
Code:
<script type=”text/javascript”>
var windowContainer = new Object();
var popW = 800;
var popH = 600;
if(screen.availWidth)
{
popW = screen.availWidth;
popH = screen.availHeight;
}
function get_cookie(Name) {
var search = Name + “=” ;
var returnvalue = “”;
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
// if the cookie exists
offset += search.length
//set the index of beginning value
end = document.cookie.indexOf(”;”, offset);
if (end == -1)
// set the index of the end of cookie value
end = document.cookie.length;
returnvalue = unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function showPopupWindow() {
if (get_cookie(’popunder’)==”){
expires = new Date(Date.parse(new Date())+1*24*60*60*1000); document.cookie=”popunder=yes;path=/;expires=”+expires.toGMTString(); var windowObj = window.open(
“http://www.example.com”, “name”, “width=”+popW+”,height=”+popH);
windowObj.blur();
window.focus();
}
else return;
}
function addListener(element, event, listener)
{
if (element) {
if(element.addEventListener) {
element.addEventListener(event, listener, false);
return true;
} else if(this.attachEvent) {
element.attachEvent(”on” + event, listener);
return true;
}
}
return false;
}
function hookLinkTags(tagId,include) {
if (document.all) {
var linkElements = document.all.tags(”A”);
for (var x = 0; x < linkElements.length; x++) {
if (!tagId || (linkElements(x).id == tagId && include == true) || (linkElements(x).id != tagId && include == false)) { addListener(linkElements(x), “click”, function() { showPopupWindow(); });
}
}
}
else if (document.getElementsByTagName) {
var linkElements = document.getElementsByTagName(”A”);
for (var x = 0; x < linkElements.length; x++) {
if (!tagId || (linkElements[x].id == tagId && include == true) || (linkElements[x].id != tagId && include == false)) {
addListener(linkElements[x], “click”, function() { showPopupWindow(); });
}
}
}
}
if (addListener(this, “load”, function() { hookLinkTags(); }) == false) {
addListener(document, “load”, function() { hookLinkTags(); });
}
</script>
Leave a Reply
You must be logged in to post a comment.
