Digital Point Forums
Send Telegram

Go Back   Digital Point Forums > Design & Development > Programming > JavaScript
Google Analytics
Log In to view
your analytics

Reply
 
Thread Tools
  #1  
Old Aug 5th 2005, 10:51 am
egdcltd egdcltd is offline
Twilight Vanquisher
 
Join Date: Apr 2005
Posts: 685
egdcltd will become famous soon enough
Javascript onClick

Is it possible to use the onClick command to call up another file? or can it interface directly with a MySQL database?
Reply With Quote
  #2  
Old Aug 5th 2005, 1:53 pm
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
Quote:
Originally Posted by egdcltd
Is it possible to use the onClick command to call up another file? or can it interface directly with a MySQL database?
I'm not sure what you are asking. JS runs client-side. All you can do is to send a request, which may do the DB work you need. For example:

function onClick(event)
{
window.location = "domain/db-handler.ext?params";
}

params will contain whatever you want to pass to MySQL.

J.D.
Reply With Quote
  #3  
Old Aug 5th 2005, 3:41 pm
egdcltd egdcltd is offline
Twilight Vanquisher
 
Join Date: Apr 2005
Posts: 685
egdcltd will become famous soon enough
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.
Reply With Quote
  #4  
Old Aug 5th 2005, 4:45 pm
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
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.
Reply With Quote
  #5  
Old Aug 6th 2005, 8:58 am
egdcltd egdcltd is offline
Twilight Vanquisher
 
Join Date: Apr 2005
Posts: 685
egdcltd will become famous soon enough
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?
Reply With Quote
  #6  
Old Aug 6th 2005, 9:21 am
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
Quote:
Originally Posted by egdcltd
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?
JS will do what you need (when available, that is). You other and better option is to analyze your logs. I would rather do this.

J.D.
Reply With Quote
  #7  
Old Aug 6th 2005, 9:39 am
egdcltd egdcltd is offline
Twilight Vanquisher
 
Join Date: Apr 2005
Posts: 685
egdcltd will become famous soon enough
Quote:
Originally Posted by J.D.
JS will do what you need (when available, that is). You other and better option is to analyze your logs. I would rather do this.

J.D.
I presume you mean manually check the outgoing clicks for each link. Unfortunately, that isn't really possible, with over 2000 links and climbing. The scoring is part of the link ordering of the directory, and really needs to be automated. Either I keep the current version, change to JavaScript, or abandon the scoring system completely.
Reply With Quote
  #8  
Old Aug 6th 2005, 10:16 am
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
Quote:
Originally Posted by egdcltd
I presume you mean manually check the outgoing clicks for each link. Unfortunately, that isn't really possible, with over 2000 links and climbing. The scoring is part of the link ordering of the directory, and really needs to be automated. Either I keep the current version, change to JavaScript, or abandon the scoring system completely.
Sorry, I shoul've been more specific. Here's some script to get you started:

<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.
Reply With Quote
  #9  
Old Aug 6th 2005, 10:18 am
egdcltd egdcltd is offline
Twilight Vanquisher
 
Join Date: Apr 2005
Posts: 685
egdcltd will become famous soon enough
Quote:
Originally Posted by J.D.
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.
I'm afraid I'm not quite sure what you mean here. Could you explain it a bit more please?
Reply With Quote
  #10  
Old Aug 6th 2005, 10:30 am
J.D. J.D. is offline
of the Nightfall
 
Join Date: Nov 2004
Posts: 1,198
J.D. has a spectacular aura aboutJ.D. has a spectacular aura about
Quote:
Originally Posted by egdcltd
I'm afraid I'm not quite sure what you mean here. Could you explain it a bit more please?
When people click on the link, the function is called. This function changes image's src attribute so that it includes the actual link. At this point, the browser will make a request to your server for this image, including url= part. Then it will go to the actual link. As a result, your logs will contain the hits for this image and search arguments will contain url=outgoing-link, which is what you are looking for. Try this (it won't actually send the link, but will show you the image):

<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.
Reply With Quote
  #11  
Old Oct 31st 2009, 6:28 pm
JohnM2009 JohnM2009 is offline
Peon
 
Join Date: Oct 2009
Posts: 1
JohnM2009 is on a distinguished road
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
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


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


All times are GMT -8. The time now is 12:30 pm.