![]() |
|
|
#1
|
|||
|
|||
|
Javascript onClick
Is it possible to use the onClick command to call up another file? or can it interface directly with a MySQL database?
|
|
#2
|
|||
|
|||
|
Quote:
function onClick(event) { window.location = "domain/db-handler.ext?params"; } params will contain whatever you want to pass to MySQL. J.D. |
|
#3
|
|||
|
|||
|
Yes, looking at my request, it wasn't very clear.
What it is, in my directory, there are coded and straight html links. The coded links, when clicked, as well as sending the user to the site, also run a cgi script (out.cgi?id=xxxx) that adds 'points' to the clicked sites' score for sorting the order of sites in the directory, by communicating with the MySQL database. I got the impression that it would be possible to use onClick to do the same function. |
|
#4
|
|||
|
|||
|
You can do this with JS - create a hidden frame and change its src on click (add link ID as a search argument). Another approach is to use redirect - hit the counting script first and pass the actual URL as a search argument. Use 302 redirect to point the browser to the actual page.
J.D. |
|
#5
|
|||
|
|||
|
I don't want to use a redirect - I'm trying to remove the redirects and replace them with straight html links.
Would the other method function like a straight html link for seo purposes? |
|
#6
|
|||
|
|||
|
Quote:
J.D. |
|
#7
|
|||
|
|||
|
Quote:
|
|
#8
|
|||
|
|||
|
Quote:
<script type="text/javascript"> function onClick(href) { document.getElementById("tracker").src = "tracker.app?url=" + encodeURI(href); return true; } </script> <img id="" src="some-image"> <a href="outgoing-link" onclick="return onClick(href)">click me</p> As a result of this, a request will be made to the tracker.app page with the URL passed as a search argument. All you will need to do is to analyze your logs for these search arguments. J.D. |
|
#9
|
|||
|
|||
|
Quote:
|
|
#10
|
|||
|
|||
|
Quote:
<script type="text/javascript"> function onClick(href) { document.getElementById("tracker").src = "http://forums.digitalpoint.com/images/misc/dps_logo.gif?url=" + encodeURIComponent(href); return false; } </script> <img id="tracker" src="http://forums.digitalpoint.com/images/misc/dps_logo.gif"> <a href="http://forums.digitalpoint.com" onclick="return onClick(href)">click me</p> Before clicking on the link, check image's properties. The click on the link and check the properties again. This is what will end up in your log file. Once you change the return value to true, the browser actually will go to the href location. Also, there's a typo in the previous example - the id should say tracker (or whatever you choose instead). It is also better to use encodeURIComponent instead (see above). J.D. |
|
#11
|
|||
|
|||
|
JD ... This was helpful but I'm having trouble getting it to work using your exact code. Is it possible my hosting or server settings are not allowing the LOGGING. Basically, the original IMG is logged and the OnClick goes to the link... but the updated IMG with the URL is not getting LOGGED. Does this go to the ACCESS Log? Any help is appreciated! ... John M
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OnClick JS in the link ahref | Hank | Link Development | 4 | Apr 23rd 2005 2:02 am |
| Change text on document onclick | strNoob | JavaScript | 1 | Apr 9th 2005 1:50 pm |
| Using Javascript and PHP | vijaykoul | JavaScript | 4 | Mar 12th 2005 7:37 am |
| Javascript version Co op? | Colindb | Setup / Validation Help | 1 | Jan 16th 2005 2:14 pm |
| Javascript Help | jalika | Search Engine Optimization | 4 | Nov 19th 2004 8:21 am |