Modal window open once when user visits website I'm trying to build simple modal window using jquery ui implementation in my custom module. I want to show this modal once when user visit my website. I choose implementation with cookie.
How to make this modal appears once to user when he visit my website? should I use hook_init?

this is my codes:

mymodule.module

/* menu callback */
function mymodule_menu() {
    $items['mymodule-popup'] = array(
        'title' =&gt; 'Join Club',
        'page callback' =&gt; 'mymodule_ajax_register',
        'page arguments' =&gt; array(1),
        'access callback' =&gt; TRUE,
        'type' =&gt; MENU_CALLBACK
    );

    return $items;
}

function mymodule_ajax_register() {
    $path = drupal_get_path('module', 'mymodule');
    drupal_add_library('system', 'ui.dialog', false);
    drupal_add_library('system', 'ui.draggable', false);
    drupal_add_js($path.'/mymodule.js');

    $output = '';
    $webform_nid = 30;
    $node = node_load($webform_nid);
    $submission = (object) array();
    $webform = drupal_get_form('webform_client_form_'.$webform_nid, $node, $submission);
    $output .= '&lt;div id="popup"&gt;';
    $output .= drupal_render($webform);
    $output .= '&lt;/div&gt;';

    return $output;
}


mymodule.js

(function ($) {
$(document).ready(function(){
    $('#popup').dialog({
        height: 'auto',
        width: 700,
        autoOpen: false,
        modal: true,
    resizable: false
    });

    $('a').click(function(){
        var status = false;
        if(this.className !== 'lightbox-processed'){
            if(!getCookie('newspopup')){
                setCookie('newspopup', 'true', 1);
                $('#popup').dialog('open');
            }else{status = true;}
            if(this.className === 'ui-dialog-titlebar-close ui-corner-all ui-state-hover'){
                $('#popup').dialog('close');
                status = true;
            }else{
            }            
        }
        if(this.id === 'bottomNavClose'){
            $('#popup').dialog('close');
        }
        return status;
    });

    function setCookie(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }

    function getCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i &lt; 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;
    }

    function deleteCookie(name) {
        setCookie(name,"",-1);
    }
});
})(jQuery);


with those codes, when user visit myweb.com/mymodule-popup then click any link/url, modal window (pop up window) will appears.

How to make modal window appears once every time user visit my website?

I need advise from you guys, Thanks before.
Why invent a new module while there are existing, well-supported ones? 

Two existing modules:


The popup_message does what you want and has a lot of features and a large installed base. 
popup_announcement - this is a relatively new module with full html support, but with only a few downloads.