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 10 of 10
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ONCLICK inside an <A> tag

    Hello,
    I have thefollowing code on a site im surrently working on to display a normal link that opens a popup window.

    Code:
    <A onClick=\"NewWin=window.open('page.php','NewWin','toolbar=no,status=no,width=500,height=300,scrollbars=yes');\" STYLE=\"text-decoration: underline;\">
    However when the link is hovered, I dont get the normal "pointing finger" icon. Ive tried including a blank HREF but that sends the parent window back to the index page. Can anyone tell me how to get the pointy finger WITHOUT going back to the insed page?

    Thank you in advance.
    "The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."

    --Tim Berners-Lee, W3C Director and Inventor of the World Wide Web

  • #2
    Regular Coder
    Join Date
    Mar 2004
    Location
    Australia
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post
    maybe....

    <a href="#" onClick="NewWin = window.open('page.php','NewWin','toolbar=no,status=no,width=500,height=300,scrollbars=yes');" STYLE="text-decoration: underline;">test</a>
    Last edited by Serex; 06-09-2004 at 11:58 AM.

  • #3
    New Coder
    Join Date
    May 2004
    Posts
    72
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats done the Job! Thank you!
    "The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."

    --Tim Berners-Lee, W3C Director and Inventor of the World Wide Web

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by LynxGrr
    when the link is hovered, I dont get the normal "pointing finger" icon.
    You have link words after your coding and you've closed the anchor? It should work.

    I take it this is PHP and that's why you have your quotation marks are escaped. However, if the link is to go directly into the HTML, try this:



    <a href="page.php"
    onClick="NewWin=window.open(this.href,'NewWin','toolbar=no,status=no,width=500,height=300,scrollbars=yes');
    return false;"
    STYLE="text-decoration:underline;">link</a>



    For PHP:


    print ("<a href=\"page.php\" onClick=\"NewWin=window.open(this.href,'NewWin','toolbar=no,status=no,width=500,height=300,scrollbars=yes');return false;\" STYLE=\"text-decoration: underline;\">link</a>");


    Note that this code is friendly to those browsers that have javascript disabled. The link will open normally for them. With javascript, the link will open in a popup (getting the URL from this.href)

    With Javascript enabled, return false; will stop the main page from going to the link in the href. (I think that's how it works, anyway)
    Last edited by llizard; 06-09-2004 at 12:23 PM. Reason: putting code snippets into smaller font so they won't stretch all over the page

  • #5
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would be best to use the href as intended so that those with javascript disabled can still follow the link. Just pass the href value to the window.open and return false for javascript enabled.


    <a href="page.php" style="text-decoration:underline"
    onclick="NewWin=window.open(this.href,'newwin','toolbar=no,status=no,width=500,height=300,scrollbars =yes');return false">


    Edit: Ooops, Lizard beat me to it.

  • #6
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Willy Duitt
    Edit: Ooops, Lizard beat me to it.
    Whoohoo!! This is a red letter day for me - not only being first but apparently it was correct as well

    (And now thanks to your post, I know how to make the fontsize a little smaller so that long lines of code won't stretch to Kingdom Come)

  • #7
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by llizard
    For PHP:


    print ("<a href=\"page.php\" onClick=\"NewWin=window.open(this.href,'NewWin','toolbar=no,status=no,width=500,height=300,scrollbars=yes');return false;\" STYLE=\"text-decoration: underline;\">link</a>");


    Note that this code is friendly to those browsers that have javascript disabled. The link will open normally for them. With javascript, the link will open in a popup (getting the URL from this.href)

    With Javascript enabled, return false; will stop the main page from going to the link in the href. (I think that's how it works, anyway)
    Hallo

    Is it possible to make this script for php, that it works only with javascript enabled?

    thanks

  • #8
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by markus
    Is it possible to make this script for php, that it works only with javascript enabled?
    Probably... but why would you want to exclude those with no javascript from being able to open the link?

  • #9
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is one Popup-code "onclick" via Link for php only with javascript enabled:

    echo "<a href=\"#\" onclick=\"window.open('test.php', 'newwindow', 'width=400,height=300'); return false;\">Open new window.</a>";

    It works fine for me.

    llizard: Your code works also fine, but with javascript disabled the link goes to the html or php page. If I add target=\"_blank\" , it works like popup.

    sorry if my english is not so good.

    Markus

  • #10
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by markus
    Here is one Popup-code "onclick" via Link for php only with javascript enabled:

    echo "<a href=\"#\" onclick=\"window.open('test.php', 'newwindow', 'width=400,height=300'); return false;\">Open new window.</a>";

    It works fine for me.
    Yes, this will indeed work for javascript viewers only. (I still can't really think of a case that one would want to prevent those with javascript disabled from opening the link but there it is.)

    Markus, I should have mentioned that the code I posted would open in the same window rather than a new one. If it is absolutely necessary for the link to open in a new window, then, yes, target=\"_blank\" will do the trick:

    Code:
    echo "<a href=\"test.php\" target=\"_blank\" 
    onclick=\"window.open(this.href, 'newwindow', 'width=400,height=300'); return false;\">Open 
    new window.</a>";


  •  

    Posting Permissions

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