Javascript to open a new popupwindow

In this article we will see how to use javascript to open a new popupwindow in a page, how to set cookies for that popup window and how to read that cookie. Also we will see how to clear cookie and again create it.

I would here tell you about how to write a javascript for:
1. Opening a pop up window
2. Setting up cookies for the pop up window
3. Reading the cookie of the pop up window.

Lets first see a javascript to open a popup window:

var newWindow;
function OpenPopUpWindowMain(Url) {
var newWindow =, 'WebMart', 'menubar=0,toolbar=0,scrollbars=1,resizable=0,statusbar=0,minimizable=0,width=820,height=500,top=100,left=100');
alert("A popup blocker was detected. \r\n To View this pop up request to change pop up blocker setting from browser");
createCookie('IsPopupOpend', 'True');
newWindow.location = Url;

Javascript to Create cookie:

function createCookie(name, value) {
var date = new Date();
var expires = "; expires="+date.toGMTString();
document.cookie = name+"="+value+expires+"; path=/";

Javascript to read that cookie:

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
return null;

Javascript to clear cookie:

function eraseCookie(name) {


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: