jquery - Open modal window when user visit website -


i'm trying build simple modal window using jquery ui implementation in custom module. want show modal once when user visit website. choose implementation cookie. how make modal appears once user when visit website? should use hook_init?

this codes:

mymodule.module

/* menu callback */ function mymodule_menu() {     $items['mymodule-popup'] = array(         'title' => 'join club',         'page callback' => 'mymodule_ajax_register',         'page arguments' => array(1),         'access callback' => true,         'type' => 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 .= '<div id="popup">';     $output .= drupal_render($webform);     $output .= '</div>';      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 < 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 codes, when user visit myweb.com/mymodule-popup click link/url, modal window (pop window) appears.

how make modal window appears once every time user visit website?

i need advise guys, before.

if want save cookie of user use user_cookie_save function (in php) , through drupal.visitor.key variable in js codes. there no need set cookie in codes retrieve drupal.

see, also, how set jquery cookie show popup once.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -