gardine
asked on
Loading a function when a hyperlink is clicked
Hello Everyone,
I am having problems loading a function (logs the users visit to a page) when a user clicks on a hyperlink. Here is the code I am using:
<a href="Some URL" target="_blank" onclick="<CFOUTPUT>#traffi c("This is the title of the page","This is the URL of the page")#</CFOUTPUT>">My Link</a>
I have four more identical links and a few regular links. The problem I am having is when any link is clicked (even the regular ones) the above code executes for every link, even though it was not the one being clicked.
Any help with this would be appreciated.
I am having problems loading a function (logs the users visit to a page) when a user clicks on a hyperlink. Here is the code I am using:
<a href="Some URL" target="_blank" onclick="<CFOUTPUT>#traffi
I have four more identical links and a few regular links. The problem I am having is when any link is clicked (even the regular ones) the above code executes for every link, even though it was not the one being clicked.
Any help with this would be appreciated.
Ur code can better go as :
<CFQuery name="x">
select * from table
</CFQuery>
<CFOUTPUT Query="x"><!--- gets u the links in the DB - as u mentioned u have 4 in ur case --->
<a href="#Url#" target="_blank" onclick="#traffic('#Title# ','#Url#') #">#LinkNa me#</a>
</CFOUTPUT>
& that shld be it !
<CFQuery name="x">
select * from table
</CFQuery>
<CFOUTPUT Query="x"><!--- gets u the links in the DB - as u mentioned u have 4 in ur case --->
<a href="#Url#" target="_blank" onclick="#traffic('#Title#
</CFOUTPUT>
& that shld be it !
Hi,
you are using #'s around the function name, do you want to call a CF function? You can't do that without sending the page back to the server. The CF function is executed server side, but, the click is executed by the user, client side. You can only call a function of a client side language, like JS for example.
HTH,
Chris
you are using #'s around the function name, do you want to call a CF function? You can't do that without sending the page back to the server. The CF function is executed server side, but, the click is executed by the user, client side. You can only call a function of a client side language, like JS for example.
HTH,
Chris
ASKER
Thank you everyone for your advice. I dont think I was specific enough. I created the above function to create a log when a user visits a specific page (I do not want to track all of them). So, for every page I would like to track I place the fonction in it. This leads me to my problem. When I link to a pdf file and open it in a new window I am unable to load my function.
ASKER
High Road?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You. I took the idea and created my own solution.
Your method of logging isn't very practical, though. For those with disabled, or unavailable Javascript, this method would not work.
You are also asking the browser to execute a CF function in an OnClick event. I would hope to assume that the resulted #traffic()# function renders another Javascript function that the browser can use.
I think what you are trying to do is execute a CF function when a user clicks a link, but CF renders completely before Javascript, therefore impossible. Use the onClick event to run a typical Javascript UDF such as onClick="<cfoutput>userVis