...

View Full Version : ONCLICK inside an <A> tag



LynxGrr
06-09-2004, 11:41 AM
Hello,
I have thefollowing code on a site im surrently working on to display a normal link that opens a popup window.


<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.

Serex
06-09-2004, 11:53 AM
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>

LynxGrr
06-09-2004, 11:57 AM
Thats done the Job! Thank you!

llizard
06-09-2004, 12:14 PM
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');re turn 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)

Willy Duitt
06-09-2004, 12:15 PM
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');re turn false">

Edit: Ooops, Lizard beat me to it. :D

llizard
06-09-2004, 12:20 PM
Edit: Ooops, Lizard beat me to it. :D

Whoohoo!! This is a red letter day for me - not only being first but apparently it was correct as well :D

(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)

markus
06-16-2004, 10:05 AM
For PHP:


print ("<a href=\"page.php\" onClick=\"NewWin=window.open(this.href,'NewWin','toolbar=no,status=no,width=500,height=300,scrollbars=yes');re turn 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

llizard
06-16-2004, 11:39 PM
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?

markus
06-18-2004, 03:38 PM
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

llizard
06-18-2004, 11:04 PM
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:



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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum