SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot think5577's Avatar
    Join Date
    Sep 2002
    Location
    Richmond, VA
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I center this pop up?

    Here is some JS I use often to create popups (images, html pages, flash pages, etc.) My question is, can I center it? Im not the JS expert but maybe some of you can help me.

    Here is the code. The first part goes in the head tags. the second part goes where the link is.

    <script language="javascript">
    function popUpWin(url, name, width, height, scroll) {
    var properties = "width=" + width + ",height=" + height + ",scrollbars=" + scroll;
    popUp = window.open(url, name, properties);
    popUp.focus();
    }

    <a href="javascriptopUpWin('whatever.html','whatever',400,500,scrollbars='no');"onMouseOver="{window.status='View';return true}"onMouseOut="{;window.status=''; return true}">

    Any help on this would be great.
    Thanks in advance.
    "Truth is a pathless land." - J. Krishnamurti


  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Location
    Dewsbury, UK
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes you can center it.
    I'll just modify your code.
    Here it is:

    <script language="javascript">
    function popUpWin(url, name, width, height, scroll) {
    var centerT=(screen.height/2)-(height/2);
    var centerL=(screen.width/2)-(width/2);
    var properties = "width=" + width + ",height=" + height + ",scrollbars=" + scroll + ",top=" + centerT + ",left=" + centerL";
    popUp = window.open(url, name, properties);
    popUp.focus();
    }

    and then call the function as you would.

    Laterz ...
    piniyini = the wackiness crazed within
    Check out my blog => toseef's blog

  3. #3
    SitePoint Zealot think5577's Avatar
    Join Date
    Sep 2002
    Location
    Richmond, VA
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks but I tried that, it didnt work.

    Is there something I should add to my "a href" if I "added" more code up top, dont I need to add more to the link?

    Thanks again though.
    "Truth is a pathless land." - J. Krishnamurti


  4. #4
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Location
    Dewsbury, UK
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry about the other code (I was in a hury at the time !)

    Anyway this works fine, I've tested it out for you.

    The code :

    <script language="javascript" type="text/javascript"><!--// TheWizSite.com
    function PopUpTWS(u,n,t,l,d,s,m,b,r,w,h,e,p)
    {
    if(e==""&&p=="")
    {
    var e=(screen.width/2)-(w/2);
    var p=(screen.height/2)-(h/2);
    }
    window.open(""+u+"",""+n+"","toolbar="+t+",location="+l+",directories="+d+",status="+s+",menubar="+m+",scrollbars="+b+",resizable="+r+",width="+w+",height="+h+",left="+e+",top="+p+"");
    }
    //--></script>

    And you call it like so:

    <a href="javascript" onclick="javascript:PopUpTWS('the url here','name of win here','toolbar','location','directories','statusbar','menubar','scrollbars','resizable','width','height','left','top');">Link Text</a>

    An example of calling it is:

    <a href="javascript" onclick="javascript:PopUpTWS('http://www.yahoo.com/','Yahoo','0','1','0','1','0','1','0','500','600','','');">Link Text</a>

    the 0 means no
    the 1 means yes

    use 0 and 1 for calling the window properties eg toolbar, directories, etc.

    if you want to center the win leave the last two fiels in the onclick blank (like I have done above)

    or you can specify the left and top measurements.


    Hope you understand, if not reply.

    (It is a bit complicated)

    Laterz ...
    piniyini = the wackiness crazed within
    Check out my blog => toseef's blog

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's one I have. Works good. Got it a long time ago, off of hotscripts or something like that, forgot.


    Code:
    function NewWindow(mypage, myname, w, h, scroll) {
      var winl = (screen.width - w) / 2;
      var wint = (screen.height - h) / 2;
      winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
      win = window.open(mypage, myname, winprops)
      if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus(); 
      }
    }
    then in the link:

    Code:
    <A HREF="site.html" ONCLICK="NewWindow(this.href,'vheaders','400','400','no');return false;">View</A>
    -Mark

  6. #6
    SitePoint Zealot think5577's Avatar
    Join Date
    Sep 2002
    Location
    Richmond, VA
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok,

    Magicsc, I tried yours, got it working but how do I make it NOT resizeable? I tried adding another 'no' down by the link, but no luck.

    Toseef,
    I tried yours also. Its crazy. I get the page I want but I also get an error with the page. "File not found." What else would be calling a page that cannot be found?

    Here is my code:
    (Head part is yours of course)
    <script language="javascript" type="text/javascript"><!--// TheWizSite.com
    function PopUpTWS(u,n,t,l,d,s,m,b,r,w,h,e,p)
    {
    if(e==""&&p=="")
    {
    var e=(screen.width/2)-(w/2);
    var p=(screen.height/2)-(h/2);
    }
    window.open(""+u+"",""+n+"","toolbar="+t+",location="+l+",directories="+d+",status="+s+",menubar="+m+",scrollbars="+b+",resizable="+r+",width="+w+",height="+h+",left="+e+",top="+p+"");
    }
    other JS here
    </script>

    Then here is my link:
    <a href="javascript" onclick="javascript:PopUpTWS('main.html','My little title','0','0','0','0','0','0','0','400','500','','');"><img src="splash1.gif" border="0"></a>

    I even tried the pop up go to google. It goes to google but another pop up comes up that says "File not found"

    Its pretty crazy.

    Thanks for all of you help everyone.
    "Truth is a pathless land." - J. Krishnamurti


  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Location
    Dewsbury, UK
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You get the error because in the href tag it says

    javascript

    it should be:

    javascript:;

    note: the is a colon followed by a semi colon after the word "javascript" which is

    :;

    I remember typing it in last time I posted, maybe SPF filters those words.

    I wonder if it shows up now.

    try the code now, it should work perfectly.

    Reply back, let me know how you got on.
    piniyini = the wackiness crazed within
    Check out my blog => toseef's blog

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    replace the javascript I gave you with this

    Code:
    function NewWindow(mypage, myname, w, h, scroll) {
      var winl = (screen.width - w) / 2;
      var wint = (screen.height - h) / 2;
      winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',nonresizable'
      win = window.open(mypage, myname, winprops)
      if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus(); 
      }
    }
    -Mark

  9. #9
    SitePoint Zealot think5577's Avatar
    Join Date
    Sep 2002
    Location
    Richmond, VA
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks Mark and Toseef.

    They both work.

    I REALLY appreciate your help. Thanks for taking the time out and posting those JSs.

    Thanks again
    "Truth is a pathless land." - J. Krishnamurti



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
  •