Get the end value of a redirected URL

How can I process this redirect URL to get “redirected value” end value using JavaScript?

Lets say this URL:

Redirected you to:

How can I get the end value of the redirect, “http://yahoo.com”, using JavaScript?

Something like this?:

var initValue = "http://ad.doubleclick.net/ad/website.com/;sect=;subs=;sz=115x77;ord=4771639";

var newValue =  ?? process(initValue); ??  // opens initValue URL and returns the redirect

document.write(newValue); //outputs "http://yahoo.com"

I don’t see any way of doing that manually, let alone with scripting.

Couldn’t I load it into an iframe and have that page get the URL from the browser address bar?

How can I use javascript to get the full URL from the address bar?

When I open a page with the doubleclick url, I get no redirect happening at all. I just get a 1x1 gif pixel, which has nothiing to do with yahoo at all.

How do you get yahoo from the doubleclick tracking image?

I was using yahoo as an example. That DoubleClick serves ads and that is a dummy url i provided. I am trying to sense if there is an ad being served- If there is no ad booked it serves a default.gif if there is an ad it servers whatever.jpg.

I am trying to write a script to sense if the DoubleClick URL is serving a real ad or a 1x1. I need to find a way to process the doubleclick url on load to see if it is serving a real ad or a blank 1x1.gif.


if (mySplitResult[1] == "1x1.gif"){
document.write("hide ad");
}else{
document.write("show ad");
}

That should be no trouble.

Just make an img element with the doubleclick link


var url = 'http://ad.doubleclick.net/ad/website.com/;sect=;subs=;sz=115x77;ord=4771639';
var img = document.createElement('img');
img.setAttribute('src', url);

Then you can check its width.


if (img.width == 1) {
	alert('This is a 1x1 ad');
}

Now you can chuck it into a function and return the result.


function testImageWidth(url) {
  var img = document.createElement('img');
  img.setAttribute('src', url);
  return img.width;
}
var url = 'http://ad.doubleclick.net/ad/website.com/;sect=;subs=;sz=115x77;ord=4771639';
if (testImageWidth(url) == 1) {
  // bugger off
} else {
  // use it
}


Perfect, thank you!

Hmm, this doesnt work in the new version of FireFox 2.0 - it does work on FF 1.0 and also in IE


<script>
// Ad is OFF - This returns a 1x1 ad
var url = 'http://ad.doubleclick.net/ad/website.com/;sect=;subs=;sz=115x77;ord=4771639';

var img = document.createElement('img');
img.setAttribute('src', url);

if (img.width == 1) {
    alert('This is a 1x1 ad');
}

function testImageWidth(url) {
  var img = document.createElement('img');
  img.setAttribute('src', url);
  return img.width;
}

if (testImageWidth(url) == 1) {
  // bugger off
  document.write("Ad Off - width="+testImageWidth(url));
} else {
  // use it
  document.write("Ad On - width="+testImageWidth(url));
}
</script>

You’re not running it from the head section are you?
You’ll have to run it from the body area for it to be able to get the sample image information.

Yes, its in the body. it works wonderfully in all browsers except FireFox 2.0 on my PC. The image width returns a value of “0” every time

The test that I’ve performed just now shows it works while in the body, but not in the head.

Please link to a sample page where you experience the trouble so that we may see what’s happening.