Results 1 to 6 of 6

Thread: Need help - Generate popup window using javascript

  1. #1
    Join Date
    Jul 2015
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Need help - Generate popup window using javascript

    Hello Friends,

    i am having hard time generating popup window in my project, using javascript. Can anyone help in this regarding??
    Thanks in advance.

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    you need to define the requirement.

    ie

    what is to be displayed in the popup

    how is it to be activated

    where is it to be positioned

    etc
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Jul 2015
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by vwphillips View Post
    you need to define the requirement.

    ie

    what is to be displayed in the popup

    how is it to be activated

    where is it to be positioned

    etc
    Can you provide an example?? I have content that goes in the popup, and a button to click.

  4. #4
    Join Date
    Nov 2014
    Location
    On A Scottish Island
    Posts
    488
    Thanks
    0
    Thanked 62 Times in 58 Posts

    Default

    Quote Originally Posted by satyaK View Post
    Can you provide an example?? I have content that goes in the popup, and a button to click.
    Ah, a homework project. Google Is Your Friend.

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

    Default

    I made a popup script some time ago. Here it is. The links on the page are the demos.

  6. #6
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <style type="text/css">
    /*<![CDATA[*/
    
    #popup1 {
      position:fixed;z-Index:101;visibility:hidden;width:200px;height:200px;background-Color:#FFCC66;
    }
    
    #popup2 {
      position:fixed;z-Index:101;visibility:hidden;width:200px;height:400px;background-Color:red;
    }
    
    .mask { /* CSS for the background mask */
     position:fixed;z-Index:100;width:100%;height:100%;left:0px;top:0px;background-Color:#FFCC66;
    /* Moz */
      opacity: .5;
    /* IE5-7 */
      filter: alpha(opacity=50);
    /* IE8 */
       -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
    }
    
    /*]]>*/
    </style></head>
    
    <body>
    
    <input type="button" name="" value="Open 1" onclick="zxcPopUp.Open('popup1',true);" />
    <input type="button" name="" value="Open 2" onclick="zxcPopUp.Open('popup2',true);" />
    <input type="button" name="" value="Close 2" onclick="zxcPopUp.Open('popup2',false);" />
    <div id="popup1" >
     <input type="button" name="" value="Close" onclick="zxcPopUp.Open('popup1',false);" />
     Your HTML code Goes Here
     </div>
    <div id="popup2" >
     Your HTML code Goes Here
    </div>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    // Simple PopUp (19-July-2015)
    //by: Vic Phillips - http://www.vicsjavascripts.org/
    
    var zxcPopUp={
    
     Open:function(id,ud){
      var o=this['zxc'+id],lst=this.lst;
      if (o){
       if  (ud===true&&lst!=o&&lst.pop.style.visibility=='visible'){
        this.animate(lst,lst.a,lst.a[2],lst.a[1],new Date(),lst.ms/2,false,o);
       }
       else {
        this.animate(o,o.a,o.a[2],o.a[ud===true?0:1],new Date(),o.ms,ud)
        ud===true?o.pop.style.visibility=o.msk.style.visibility='visible':null;
        this.resize(o);
        this.lst=o;
       }
      }
     },
    
     Init:function(o){
      var id=o.PopUpID,c=o.MaskClass,ms=o.Animate,pop=document.getElementById(id);
      if (pop){
       var mk=document.createElement('DIV'),w=pop.offsetWidth,h=pop.offsetHeight,msk;
       mk.style.position='fixed';
       msk=mk.cloneNode(false);
       msk.style.left=msk.style.top=mk.style.width=mk.style.height=mk.style.right=mk.style.bottom='0px';
       document.body.appendChild(mk);
       msk.className=c;
       msk.style.width='100%';
       typeof(c)=='string'?document.body.appendChild(msk):null;
       pop.style.visibility=msk.style.visibility='hidden';
       o.id=id;
       o.pop=pop;
       o.a=[[0,w,h,0],[h/2,w/2,h/2,w/2],[h/2,w/2,h/2,w/2]];
       o.msk=msk
       o.mk=mk;
       o.ms=typeof(ms)=='number'&&ms>20?ms:1000;
       this.addevt(msk,'click','Open',id,false);
       this['zxc'+id]=this.lst=o;
       this.resize(o);
       this.addevt(window,'resize','resize',o);
      }
     },
    
     animate:function(o,a,f,t,srt,mS,ud,nxt){
      clearTimeout(a[3]);
      var oop=this,ms=new Date().getTime()-srt,n=[],z0=0;
      for (;z0<f.length;z0++){
       n[z0]=Math.max((t[z0]-f[z0])/mS*ms+f[z0],0);
      }
      oop.clip(o,n);
      if (ms<mS){
       a[3]=setTimeout(function(){ oop.animate(o,a,f,t,srt,mS,ud,nxt); },10);
      }
      else {
       oop.clip(o,t);
       ud!==true?o.pop.style.visibility=o.msk.style.visibility='hidden':null;
       nxt?oop.Open(nxt.id,true):null;
      }
     },
    
     clip:function(o,n){
      if (isFinite(n[0])&&isFinite(n[1])&&isFinite(n[2])&&isFinite(n[3])){
       o.a[2]=n;
       o.pop.style.clip='rect('+Math.ceil(n[0])+'px,'+Math.ceil(n[1])+'px,'+Math.ceil(n[2])+'px,'+Math.ceil(n[3])+'px)';
      }
     },
    
     resize:function(o){
      o.pop.style.left=(o.mk.offsetLeft-o.pop.offsetWidth)/2+'px'
      o.pop.style.top=(o.mk.offsetTop-o.pop.offsetHeight)/2+'px'
      o.msk.style.height=o.mk.offsetTop+'px';
     },
    
     addevt:function(o,t,f,p,p1){
      var oop=this;
      o.addEventListener?o.addEventListener(t,function(e){ return oop[f](p,p1);},false):o.attachEvent?o.attachEvent('on'+t,function(e){ return oop[f](p,p1); }):null;
     }
    
    }
    
    
    zxcPopUp.Init({
     PopUpID:'popup1', // the unique ID name of the PopUp.                   (string)
     MaskClass:'mask', //(optional) the class name of the PopUp mask.        (string, default - no mask)
     Animate:1000      //(optional) the animation duration in milli seconds. (number, default - 1000)
    });
    
    zxcPopUp.Init({
     PopUpID:'popup2'
    });
    
    /*]]>*/
    </script>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

Similar Threads

  1. Replies: 1
    Last Post: 02-28-2014, 07:43 PM
  2. Mastering popup window using javascript
    By Webiter in forum JavaScript
    Replies: 0
    Last Post: 12-30-2011, 08:04 PM
  3. Javascript popup window help
    By choice43015 in forum JavaScript
    Replies: 4
    Last Post: 12-16-2008, 10:23 PM
  4. Javascript Help with Popup window
    By fmrock in forum JavaScript
    Replies: 1
    Last Post: 09-28-2007, 04:01 AM
  5. Replies: 3
    Last Post: 08-31-2006, 09:00 PM

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
  •