SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    http://ad.doubleclick.net/ad/website...77;ord=4771639

    Redirected you to:
    http://yahoo.com

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

    Something like this?:
    Code JavaScript:
    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"

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    I don't see any way of doing that manually, let alone with scripting.

  3. #3
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    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?

  5. #5
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

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

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    That should be no trouble.

    Just make an img element with the doubleclick link

    Code JavaScript:
    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.

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

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

    Code JavaScript:
    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
    }
    Last edited by paul_wilkins; Dec 18, 2007 at 02:36.

  7. #7
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect, thank you!

  8. #8
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, this doesnt work in the new version of FireFox 2.0 - it does work on FF 1.0 and also in IE

    Code JavaScript:
    <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>
    Last edited by ripcurlksm; Dec 18, 2007 at 15:16.

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    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.

  10. #10
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    857
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •