The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 19, 2019, 05:21:46 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: JS redirect but meanwhile still trigger a counter.  (Read 4054 times)
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« on: April 24, 2007, 08:50:57 PM »

I have pages that look like this
<html>
<head>
<script>
XXXXX send info to another server
document.location = "XXXXX";
</script>
</head>
............
I have no control over the server. I can only do JS.
Before I hit document.location I want info to be sent to another server which i do control.
The document.location has to be in the head part of page, because i want the redirect to happen,
before page has completely loaded.

Any ideas ?

Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: April 24, 2007, 10:16:21 PM »

There are 2 issues here.

First is the multiple domain bit - can't use Ajax - it's single domain. iFrames will work, and images (my personal choice) will work but...
Second problem: IE particularly will stop loading things and resources the moment it notices that it is leaving the current page.

IE., as soon as you say top/document.location, will abandon any loading operation - it will even stop animating GIFs. This would not be a problem, except that inline code in the header is going to go really fast, and it is a sure bet that the JS will get to the change in location line before it has fired off the thread to go get <the whatever that is your beacon>. The real problem here is that Javascript does not offer a blocking Sleep-like function. The only way to delay execution in JS is to either set a timeout or an interval. One other technique is to not count on a delay, but rather to count on a completion ie., when something is all done. The problem here, is that your page will have loaded before the timeout/event pops.  There are a couple ways to obscure the PERCEPTION of the page loading... we can handle that in a bit ...

but assuming that we do, here's my suggestion for the dandelion (my personal nom-de-technique for little uni-directional snippets of information blowing towards my server from the client):

I'm thinking you need to create an image and load it inline:

myImage = new Image();
myImage.onLoad = function() { top.location = 'http://anotherdomain.com'; }
myImage.src = 'http://nopsDomain.com/aURL.php?parm1=this&parm2=that';
// obviously, where the url above is a string construct of the data you want to pass...

this, put in the header, will fire off an immediate request for a graphic - in fact, since it is in the header it will be before any other requests for graphics have fired off. It will be very fast, BUT the browser will have gotten and started to render your HTML before it arrives. Note that I think you should have a 1x1 pixel .GIF that you return to absolutely maximize the speed at which you will respond to the event. I like this method because it will move as quickly as possible, regardless of connection or machine speed.

Now... what's the problem with cloaking/hiding/obscurring the page content? Why can't we do a little JS and obscure the opening of the page?

/p
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
thedarkness
Lifer
*****
Offline Offline

Posts: 585



View Profile
« Reply #2 on: April 24, 2007, 10:37:44 PM »

Anotehr approach would be to do your "document.location = " to a page on the server you do control including the parameters you want to pass and the ultimate url you want to redirect to then issue a redirect from there. This approach has downsides (loss of referrer, etc. ) and I'm sure you've considered (and discounted) it but I offer it up for someone in a similar situation where it presents a viable option.

Cheers,
td
Logged

"I want to be the guy my dog thinks I am."
 - Unknown
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #3 on: April 24, 2007, 10:37:59 PM »

I tried doing a normal
then i tried with a CSS style file.
But exactly what u say happens. the page redirects before the image/file even starts to load.

Code:
myImage = new Image();
myImage.onLoad = function() { top.location = 'anotherdomain.com'; }
myImage.src = 'nopsDomain.com/aURL.php?parm1=this&parm2=that';
// obviously, where the url above is a string construct of the data you want to pass...
It will work thanx Smiley
I should be also able to put an onError so if my server is down then i will still redirect.

Now... what's the problem with cloaking/hiding/obscurring the page content? Why can't we do a little JS and obscure the opening of the page?

Errrrr yah
it is for my son's science fair project where yah the page gets redirected to one of those places where hopefully user
is running IE6 and 20 popups nail them. And part of the science project is user should not know what is happening.
Yah thats it.
Logged
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #4 on: April 24, 2007, 10:39:07 PM »

Errrrr yah
it is for my son's science fair project where yah the page gets redirected to one of those places where hopefully user
is running IE6 and 20 popups nail them. And part of the science project is user should not know what is happening.
Yah thats it.

I thought that was it  ROFLMAO
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
nop_90
Global Moderator
Lifer
*****
Offline Offline

Posts: 2203


View Profile
« Reply #5 on: April 24, 2007, 10:39:59 PM »

Anotehr approach would be to do your "document.location = " to a page on the server you do control including the parameters you want to pass and the ultimate url you want to redirect to then issue a redirect from there. This approach has downsides (loss of referrer, etc. ) and I'm sure you've considered (and discounted) it but I offer it up for someone in a similar situation where it presents a viable option.
Problem is my vps is unreliable, so if it is down then i lose the user.
Logged
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!