Results 1 to 3 of 3

Thread: modal pop up on load not working

  1. #1
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default modal pop up on load not working

    i have found some code to launch a pop up on the load of a webpage but it isnt popping up
    i got the code from here
    http://www.queness.com/post/77/simpl...indow-tutorial

    the code i have used is
    Code:
    <script>
    
    $(document).ready(function () {
      //id is the ID for the DIV you want to display it as modal window
      launchWindow('dialog'); 
    
    	//select all the a tag with name equal to modal
    	$('a[name=modal]').click(function(e) {
    		//Cancel the link behavior
    		e.preventDefault();
    		//Get the A tag
    		var id = $(this).attr('href');
    	
    		//Get the screen height and width
    		var maskHeight = $(document).height();
    		var maskWidth = $(window).width();
    	
    		//Set height and width to mask to fill up the whole screen
    		$('#mask').css({'width':maskWidth,'height':maskHeight});
    		
    		//transition effect		
    		$('#mask').fadeIn(1000);	
    		$('#mask').fadeTo("slow",0.8);	
    	
    		//Get the window height and width
    		var winH = $(window).height();
    		var winW = $(window).width();
                  
    		//Set the popup window to center
    		$(id).css('top',  winH/2-$(id).height()/2);
    		$(id).css('left', winW/2-$(id).width()/2);
    	
    		//transition effect
    		$(id).fadeIn(2000); 
    	
    	});
    	
    	//if close button is clicked
    	$('.window .close').click(function (e) {
    		//Cancel the link behavior
    		e.preventDefault();
    		$('#mask, .window').hide();
    	});		
    	
    	//if mask is clicked
    	$('#mask').click(function () {
    		$(this).hide();
    		$('.window').hide();
    	});			
    	
    });
    
    </script>
    HTML Code:
    <!-- #dialog is the id of a DIV defined in the code below -->
    <div id="boxes">
    
    	
    	<!-- #customize your modal window here -->
    
    	<div id="dialog" class="window">
    		<b><img src="../../resources/img/general/Opening-hours-2016.jpg" width="640" height="460"></b> | 
    		
    		<!-- close button is defined as close class -->
    		<a href="#" class="close">Close</a>
    
    	</div>
    
    	
    	<!-- Do not remove div#mask, because you'll need it to fill the whole screen -->	
      <div id="mask"></div>
    </div>
    css
    Code:
    <style>
    
    /* Z-index of #mask must lower than #boxes .window */
    #mask {
      position:absolute;
      z-index:9000;
      background-color:#000;
      display:none;
    }
      
    #boxes .window {
      position:fixed;
      width:440px;
      height:200px;
      display:none;
      z-index:9999;
      padding:20px;
    }
    
    
    /* Customize your modal window here, you can add background image too */
    #boxes #dialog {
      width:640px; 
      height:560px;
    }
    </style>

  2. #2
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Try this:
    Code:
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <title>Simple jQuery Modal Window</title>
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    
    <script>
    
    $(document).ready(function() {	
    	
    //Put in the DIV id you want to display
    launchWindow('#popup');
    	
    //if close button is clicked
    $('.window .close').click(function () {
    $('#mask').hide();
    $('.window').hide();
    });		
    	
    //if mask is clicked
    $('#mask').click(function () {
    $(this).hide();
    $('.window').hide();
    });			
    	
    $(window).resize(function () {
    	 
    var box = $('#boxes .window');
     
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
          
    //Set height and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});
                   
    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
    
    //Set the popup window to center
    box.css('top',  winH/2 - box.height()/2);
    box.css('left', winW/2 - box.width()/2);
    	 
    });	
    	
    });
    
    function launchWindow(id) {
    	
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    	
    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});
    		
    //transition effect		
    $('#mask').fadeIn(1000);	
    $('#mask').fadeTo("slow",0.8);	
    	
    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
                  
    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);
    	
    //transition effect
    $(id).fadeIn(2000); 
    
    }
    
    </script>
    
    <style>
    
    a {color:#333; text-decoration:none}
    a:hover {color:#ccc; text-decoration:none}
    
    #mask {
    position:absolute;
    left:0;
    top:0;
    z-index:9000;
    background-color:#000;
    display:none;
    }
      
    #boxes .window {
    position:fixed; 
    width:440px;
    height:200px;
    display:none;
    z-index:9999;
    padding:20px;
    }
    
    #boxes #popup {
    width:375px; 
    height:203px;
    padding:10px;
    background-color:#ffffff;
    font-family: verdana;
    font-size: 14px
    }
    
    .close {
    float: right; 
    padding: 10px; 
    padding-top: 0; 
    margin-right: -10px; 
    margin-top: -10px; 
    font-family: verdana; 
    font-size: 22px;
    }
    
    </style>
    
    </head>
    <body>
    <h2 style="text-align: center">Simple jQuery Modal Window</h2>
    
    <div id="boxes">
    
    <div id="popup" class="window">
    <a href="javascript: void(0)" class="close" >X</a>
    <br>This Is A Simple Modal Window
    </div>
    
    <!-- Mask to cover the whole screen -->
    <div id="mask"></div>
    </div>
    
    </body>
    </html>

  3. #3
    Join Date
    Nov 2011
    Posts
    74
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    thanks that worked

    Quote Originally Posted by molendijk View Post
    Try this:
    Code:
    <!doctype html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <title>Simple jQuery Modal Window</title>
    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    
    <script>
    
    $(document).ready(function() {	
    	
    //Put in the DIV id you want to display
    launchWindow('#popup');
    	
    //if close button is clicked
    $('.window .close').click(function () {
    $('#mask').hide();
    $('.window').hide();
    });		
    	
    //if mask is clicked
    $('#mask').click(function () {
    $(this).hide();
    $('.window').hide();
    });			
    	
    $(window).resize(function () {
    	 
    var box = $('#boxes .window');
     
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
          
    //Set height and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});
                   
    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
    
    //Set the popup window to center
    box.css('top',  winH/2 - box.height()/2);
    box.css('left', winW/2 - box.width()/2);
    	 
    });	
    	
    });
    
    function launchWindow(id) {
    	
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    	
    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});
    		
    //transition effect		
    $('#mask').fadeIn(1000);	
    $('#mask').fadeTo("slow",0.8);	
    	
    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
                  
    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);
    	
    //transition effect
    $(id).fadeIn(2000); 
    
    }
    
    </script>
    
    <style>
    
    a {color:#333; text-decoration:none}
    a:hover {color:#ccc; text-decoration:none}
    
    #mask {
    position:absolute;
    left:0;
    top:0;
    z-index:9000;
    background-color:#000;
    display:none;
    }
      
    #boxes .window {
    position:fixed; 
    width:440px;
    height:200px;
    display:none;
    z-index:9999;
    padding:20px;
    }
    
    #boxes #popup {
    width:375px; 
    height:203px;
    padding:10px;
    background-color:#ffffff;
    font-family: verdana;
    font-size: 14px
    }
    
    .close {
    float: right; 
    padding: 10px; 
    padding-top: 0; 
    margin-right: -10px; 
    margin-top: -10px; 
    font-family: verdana; 
    font-size: 22px;
    }
    
    </style>
    
    </head>
    <body>
    <h2 style="text-align: center">Simple jQuery Modal Window</h2>
    
    <div id="boxes">
    
    <div id="popup" class="window">
    <a href="javascript: void(0)" class="close" >X</a>
    <br>This Is A Simple Modal Window
    </div>
    
    <!-- Mask to cover the whole screen -->
    <div id="mask"></div>
    </div>
    
    </body>
    </html>

Similar Threads

  1. Resolved DHTML Modal window v1.1 error before the wondows to load
    By alakbd in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 10-09-2012, 11:42 PM
  2. Modal once per session not working
    By emgproductions in forum Dynamic Drive scripts help
    Replies: 5
    Last Post: 11-24-2009, 03:51 PM
  3. DHTML Modal window v1.1-How to load record per ID for update form
    By kashifmalik in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 11-19-2008, 07:13 PM
  4. _blank is not working in modal dialog
    By kiran in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 06-22-2005, 01:40 PM
  5. _blank is not working in modal dialog
    By kiran in forum JavaScript
    Replies: 1
    Last Post: 06-16-2005, 11:10 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •