Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pop up link (link that pops up a window)

    first i got this script from javascriptkit.com

    <script>

    function openpopup(){
    var popurl="mail.html"
    winpops=window.open(popurl,"","width=430,height=365,toolbar,status,")
    }

    </script>

    then the link will be like this

    <a href="javascriptpenpopup()"

    but that only goes for 1 target (mail.html) then i tried to make another link that pops up a window with fixed size and atributes

    <a href="javascript:window.open('shout.html',
    'win1','width=450,height=300,menubar,scrollbars')"">

    it does pops up a window, but the first window (where the link is) becomes a blank page

    thanks in advance before

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Try this (no pun intended):

    Code:
    <a href="shout.html" onclick="window.open(this,'win1','width=450,height=300,menubar=1,scrollbars=1');return false;">shout</a>
    The this after window.open refers to the URL after href="

    The beauty of it is that it will still open even if javascript is disabled.


    I have just recently been learning about popup windows and linking to and from them. The following may be of help to you:
    http://llizard.crosswinds.net/cwc/popuplinks.html

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    The this keyword there refers to the current element which is the <a>

    <a href="shout.html" onclick="window.open(this.href, ...
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    The this keyword there refers to the current element which is the <a>

    <a href="shout.html" onclick="window.open(this.href, ...
    oh rats. I thought that's what I just said....

    the .href is optional (at least I think it's optional....)

  • #5
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow thanks
    so without the this the window will go somewhere else, i got it thx

  • #6
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by toya
    so without the this the window will go somewhere else, i got it thx
    Actually, it seems that without the onclick= and return false;, the window will go somewhere else.

    You can still use:

    Code:
    <a href="shout.html" onclick="window.open('shout.html','win1','width=450,height=300,menubar=1,scrollbars=1');
    return false;">shout</a>
    but the "this" or "this.href" after onclick=window.open( makes it so you don't have to enter the URL twice in the same link.

    (Hope that made sense)

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by llizard
    oh rats. I thought that's what I just said....
    You said it also in your site.

    Quote Originally Posted by llizard
    the .href is optional (at least I think it's optional....)
    I tested it in some of the browsers and yes, it turned out to be really optional.
    It goes to show that the default property for the this keyword in <a> tag is the href property.
    But, IMHO, it is better to explicitly define the intended property to avoid confusion and provide consistency of usage of the this keyword in all HTML elements.
    Last edited by glenngv; 06-04-2004 at 03:52 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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