Javascript load external URL's?

R

ReGenesis0

Okay, this involves integrating javascript with PHP (though you don't
have to know PHP to understand my question.)

I have a page. It has a link. When someoen clicks on the link, iw ant
to know. But- it's an OFFSITE link. Fundamentally untrackable.

This is my comprimise... when you click on that link, Javascript
executes a function in half-second before the page unloads. That
fuction loads an external image. (purely into memory with a .src=) I'm
using PHP to coun the number of times that image is loaded.

This works, for the most part. but my code looks like-

teston.src = "test.php?mode=increment";

(The query mode set after the file name is what tells php to increment
the databse, clearly.)

Now- here's the crux- there's no fundamental need for this to be an
image. (text.php actually returns blank, it doesnt' bother sendign an
image file.) Is there a way OTHER than using image.src to send a
http:// query out of Javascript? (I know there must be, but my js is
SOO rusty, last time I coded heavily was when Netscape introduced their
now-depricated layers implementation.)

Also- is there a... better way to do this? This seems like the only
possible way to tackle this, but I'm operatining the dark here. I
assume someoen else has tried this before me.

-Derik
 
E

Erwin Moller

Okay, this involves integrating javascript with PHP (though you don't
have to know PHP to understand my question.)

I have a page. It has a link. When someoen clicks on the link, iw ant
to know. But- it's an OFFSITE link. Fundamentally untrackable.

This is my comprimise... when you click on that link, Javascript
executes a function in half-second before the page unloads. That
fuction loads an external image. (purely into memory with a .src=) I'm
using PHP to coun the number of times that image is loaded.

This works, for the most part. but my code looks like-

teston.src = "test.php?mode=increment";

(The query mode set after the file name is what tells php to increment
the databse, clearly.)

Now- here's the crux- there's no fundamental need for this to be an
image. (text.php actually returns blank, it doesnt' bother sendign an
image file.) Is there a way OTHER than using image.src to send a
http:// query out of Javascript? (I know there must be, but my js is
SOO rusty, last time I coded heavily was when Netscape introduced their
now-depricated layers implementation.)

Also- is there a... better way to do this? This seems like the only
possible way to tackle this, but I'm operatining the dark here. I
assume someoen else has tried this before me.

-Derik

Hi Derik,

You have several other options, allthough I do not understand why you
image-source switch doesn't work. (It should).

Alternatively:
1) Use a hidden frames.
2) Use Ajax.

If you are unfamiliar with AJAX, start here for a great tutorial to master
the Ajaxbasics in one hour: www.w3schools.com/ajax

Regards,
Erwin Moller
 
R

ReGenesis0

You have several other options, allthough I do not understand why you
image-source switch doesn't work. (It should).

It does work- I find it inelegant to be using an image construct to
load a non-image, and am wondering if I can load this URL (well, quwery
it, since it never actually loads anything, the magic is in makign the
request) withotu creatign the javascript image construct.

In short- I'm wondering if there's a more 'mature' implementation of
this approach.
Alternatively:
1) Use a hidden frames.

Pfft, and leave the user stuck int he frame when clicking out? No way.
2) Use Ajax.

*looks at Ajax*

Yeah, that's what I'm looking for. A more mature, elegant application
of the same technologies involved. ;-)

Thanks!

-Derik
 
R

Randy Webb

(e-mail address removed) said the following on 5/17/2006 4:46 PM:
It does work- I find it inelegant to be using an image construct to
load a non-image, and am wondering if I can load this URL (well, quwery
it, since it never actually loads anything, the magic is in makign the
request) withotu creatign the javascript image construct.

What is so "inelegant" about an approach that is almost fool proof?
In short- I'm wondering if there's a more 'mature' implementation of
this approach.


Pfft, and leave the user stuck int he frame when clicking out? No way.


*looks at Ajax*

Yeah, that's what I'm looking for. A more mature, elegant application
of the same technologies involved. ;-)

Two things:
1) It is *not* the same technologies
2) With that "mature elegance", you lose reliability.
 
E

Erwin Moller

Randy said:
(e-mail address removed) said the following on 5/17/2006 4:46 PM:

What is so "inelegant" about an approach that is almost fool proof?


Two things:
1) It is *not* the same technologies
2) With that "mature elegance", you lose reliability.

Yep, I second Randy's opinion completely.

About the hidden frame: The user will NOT EVEN notice it, let alone (s)he is
stuck in it.
A hidden frame is just a frame with 0 for width or height.
You change the location/URL of that frame, so it loads a new page, in this
case you just call your script.
The user won't notice and won't see a thing. (Only the animation in some
browsers indicating some networkactivity is going on.)

I agree however, for other reasons, that frames should be avoided.

If you choose to go Ajax, be aware that this will only work on modern
browsers, the ones that support some implementation of a httpxmlObject, or
whatever they are called on the different browsers.

The trick with the image works on all browsers.

Also be aware that all tricks/solutions discussed so far ALL rely on
Javascript, which is disabled by some.
If you want to count ALL your clicks (also the ones from browsers that have
JS disabled), you have little more choice than hitting the page that counts
directly, and let it redirect to the 'real' location when the increasing is
done.

Good luck.

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top