473,738 Members | 7,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onClick to call script with href and link test as parms?

JS Programmers, "I'm a server-side coder PHP, Postgres etc...

My question; Given the following anchor

<a href="http://www.somesite.co m/somefile.html"> link text</a>

Is there a way to code an onClick event to call a script and pass the
href URL and link text?

That is; We'd like to put an identical piece of JS code into each
anchor tag essentially to have the anchors, when clicked call one
script which does logging of the URL and link text before doing a
redirect.

With no working knowledge in JS, only some past background reading, my
assumption is that something like this may be valid;

onClick="load(l oggingScript.ph p?url=anchor.ur l&text=anchor.t ext)"

Please advise.

TIA
--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 28 '05 #1
4 16423
Jerry Sievers wrote:
JS Programmers, "I'm a server-side coder PHP, Postgres etc...

My question; Given the following anchor

<a href="http://www.somesite.co m/somefile.html"> link text</a>

Is there a way to code an onClick event to call a script and pass the
href URL and link text?

That is; We'd like to put an identical piece of JS code into each
anchor tag essentially to have the anchors, when clicked call one
script which does logging of the URL and link text before doing a
redirect.

With no working knowledge in JS, only some past background reading, my
assumption is that something like this may be valid;

onClick="load(l oggingScript.ph p?url=anchor.ur l&text=anchor.t ext)"

Please advise.

TIA


I'd go with something like this (based on your above suggestion):
onClick="locati on.href='/loggingScript.p hp?url='+
this.href+'&tex t='+this.text;r eturn(false);"

For the record, though, this can break any other onClick code you may
have, as well as making the code more unreadable.

Jul 28 '05 #2
Christopher J. Hahn wrote:
I'd go with something like this (based on your above suggestion):
onClick="locati on.href='/loggingScript.p hp?url='+
this.href+'&tex t='+this.text;r eturn(false);"

For the record, though, this can break any other onClick code you may
have, as well as making the code more unreadable.


Ugh... again, I do this thing with text properties.

..text won't work.

That, and the ampersand *should* be escaped into an HTML entity
(&amp;). You *may* also need to do the same with the equal sign (not
really sure, but = will do it).

onClick="locati on.href='/loggingScript.p hp?url='+
this.href+'&amp ;text='+this.in nerHTML;return( false);"
Be advised that this will include any HTML between the <a> and </a>
tags as part of the link text, and that innerHTML isn't part of any
written standards.
The more complicated solution is to implement a function:

function load( href, text ) {
location.href =
'/loggingScript.p hp?url=' + href + '&text=' +
text.replace( /<.*?>/g, '' );

return false;
}
and an onlick:
onclick="return (load(this.href ,this.innerHTML ))"

Though HTML *entities* (&thing; constructs) within the link text will
not be converted.

This will also still break any other onclick code you may have wanted
to wrap in your <a> tags.
For those, use:
onclick="old_on click_code_here ;return(load(.. .

et cetera.

Jul 28 '05 #3
"Jerry Sievers" <je***@jerrysie vers.com> wrote in message
news:m3******** ****@prod01.jer rysievers.com.. .
JS Programmers, "I'm a server-side coder PHP, Postgres etc...

My question; Given the following anchor

<a href="http://www.somesite.co m/somefile.html"> link text</a>

Is there a way to code an onClick event to call a script and pass the
href URL and link text?

That is; We'd like to put an identical piece of JS code into each
anchor tag essentially to have the anchors, when clicked call one
script which does logging of the URL and link text before doing a
redirect.

With no working knowledge in JS, only some past background reading, my
assumption is that something like this may be valid;

onClick="load(l oggingScript.ph p?url=anchor.ur l&text=anchor.t ext)"

Please advise.

TIA


Horribly bad idea.

"Note that you should not build a redirect page that takes an arbitrary
URL, as this can be abused in cross-domain attacks. Always build your
redirect pages to take an opaque identifier that then maps back to a URL
you control and know to be trustworthy."

<url: http://blogs.msdn.com/ptorr/archive/...17/439798.aspx />

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 28 '05 #4
"Christophe r J. Hahn" <cj****@gmail.c om> writes:
Jerry Sievers wrote:
Is there a way to code an onClick event to call a script and pass the
href URL and link text?

I'd go with something like this (based on your above suggestion):
onClick="locati on.href='/loggingScript.p hp?url='+
this.href+'&tex t='+this.text;r eturn(false);"


Thank you for this suggestion as it was the basis for a simple
solution to my project needs. Within the scope of the project, some
security concerns raised by another respondent were considered but
dismissed.
function doit(obj)
{
location.href=' logger.php?url= '+obj.href+'&te xt='+obj.text;
return(false);
}

<a href="foobar.ht ml"
onClick="return (doit(this))"this is it</a>


--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 31 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
35239
by: Matt | last post by:
I created 3 hyperlinks, when the user click each link, it will change the color of the text of a link. For example, when user clicks Link1, text Link1 will become red color, but Link2 and Link3 unchange. Here's my attempts, any ideas?? <script language="javascript"> function changecolor (i) { document.i.fontcolor = red; }
17
61442
by: Mike Gratee | last post by:
Is it possible to use JavaScript to cause the browser to click a link on a page and have the browser act exactly like the user had clicked on the link directly? In other words, I need to programmatically issue a JavaScript statement which causes the browser to act just like the user clicked on a link in my page. And if that link has an onClick JS event defined, I'd want that onClick event to execute too, exactly the same as if the user...
2
9172
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display in the status bar 'Symantec Corporation' whenever anyone mouses over (onMouseOver) my image or link OR when one clicks while holding the left mouse down (onClick) on the same image or link. Upon releasing the mouse (onMouseOut), the
9
4500
by: Marco Krechting | last post by:
Hi All, I have a page with a list of hyperlinks. I want to save information in a cookie about the fact that I entered an hyperlink or not. When I click one of the hyperlinks I want this stored in a cookie and a small bullit shown in front of the hyperlink, so when I reload the page I can immediately see which hyperlinks I already visited that day.
53
81731
by: usenet | last post by:
See <ul> <li><a name="link1" onClick="alert(this.name);return false;" href="#">Link1</a></li> <li><a name="link2" href="javascript:alert(this);">Link2</a></li> <li>Item 3</li> </ul> Clicking on the first list item gives me "link1" because "this" refers
11
3031
by: GaryB | last post by:
Hi Guys, I've been battling with this one for hours - I hope that you can help me! My code modifies the <aon a page, from a standard document link into a link with a tailored onclick event. It works perfectly (assigning the correct images and the correct onclick events to the correct <atags):
9
3227
by: monomaniac21 | last post by:
hi all i want to use hyperlinks to 'load' content by changing the display of div tags. the problem i have is that unless i specify a href the anchor does not change the mouse pointer on hover even if display is set to block. it only look changes when there is a href there. but if i have a href there then when i click it will load the page, which i dont want. how can i get the anchor to look like a proper link where the users pointer...
9
8559
by: whitgurley | last post by:
I've searched the web as well as I can for a solution to this problem but have found nothing and just don't know enough about JavaScript to figure out what's going. What I'm trying to do is convert this script: <a href="#" onclick="MM_goToURL('parent.frames','color2.html');return document.MM_returnValue">TEST</a> ....to something that I can use within a Flash movie, which as far as I can tell means that it needs to reside in the...
1
3680
by: Miroslav Stampar [MCSD.NET / Security+] | last post by:
I have a problem that is best described by following code: <a href="http://www.google.com" onclick="new Image().src=\'http:// www.example.com/process.cgi?p=1\'">Google</a> I want to call cgi script before a link is clicked. Upper example works as a standalone (AS IS), but... But, when I attach onclick event programmaticaly, clicked link loads to fast so image/CGI script doesn't have time to preload. Do you have
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.