Comments on: Getting a fully qualified URL https://j11y.io/snippets/getting-a-fully-qualified-url/ Sun, 22 Mar 2015 15:39:22 +0000 hourly 1 https://wordpress.org/?v=5.0.13 By: James https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-513 Mon, 19 Oct 2009 20:36:23 +0000 https://j11y.io/?p=446#comment-513 @Kyle, thanks for the “http://” tip!

@Zach, funnily enough, that StackOverflow thread you just linked to was started by me (“J-P”)!

]]>
By: Zach Leatherman https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-512 Mon, 19 Oct 2009 20:22:50 +0000 https://j11y.io/?p=446#comment-512 Actually, a co-worker pointed out to me that the removeAttribute will not work properly either. I found a silver-bullet approach using innerHTML over at http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue

]]>
By: Zach Leatherman https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-511 Fri, 16 Oct 2009 19:18:21 +0000 https://j11y.io/?p=446#comment-511 Instead of
img.src = null;

This should work without making a request:
img.removeAttribute(‘src’);

I would strongly encourage you to amend the article with this information, I was seeing serious issues with corrupted server-side models because of this extra “null” request, which would resolve to something like:
https://j11y.io/javascript/null

Thanks,
Zach

]]>
By: Kyle Simpson https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-510 Thu, 07 May 2009 15:15:37 +0000 https://j11y.io/?p=446#comment-510 I just tried this in IE7.

Results: a request is made when you set img.src, but then it looks like it’s canceled when you set src=null. So, technically, a request is fired off, but the page isn’t suffering from the waiting for the response.

However, I watched the server logs, and the server doesn’t even receive the initial request, but it does receive the request for “null”, which of course (usually) will return a 404. So that kind of defeats the purpose. Trading one request for another isn’t that helpful.

However, if you set img.src = “http://”, then it makes a dead request (no server load taken up), and should have little to no overhead in the browser processing/waiting (since this is javascript and asynch/non-blocking).

The bad part is the server does still receive the initial script url request (in the logs), but again, IE7 has already abandoned the request by that point so the browser doesn’t pay the penalty to process the response.

————-

Also, I tried the a.href stuff, and that doesn’t work when inserted by javascript, at least not in IE7. It just returns the same src you set to it. I even tried inserting the link into the body of the page, still no go.

]]>
By: James https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-509 Thu, 22 Jan 2009 21:33:05 +0000 https://j11y.io/?p=446#comment-509 Technically, a server request is made but since the ‘src’ is set to null it just ends up being a request to the same page which means the overhead is non existent (I’m not totally sure about this though). It might be worth introducing a compromise:

function qualifyURL(url) {
    var a = document.createElement('a');
    a.href = url;
    if (/^http:///.test(url)) {
        // IE7, FF, Op, Sf
        return a.href;
    } else {
        // IE6
        var img = document.createElement('img');
        img.src = url;
        return img.src;
    }
}
]]>
By: Thomas Milburn https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-508 Thu, 22 Jan 2009 19:15:36 +0000 https://j11y.io/?p=446#comment-508 It might not be completely your own but I like your modification and its a neat hack! Could you explain how your modification actually works. When would javascript normally make the server request. I would of thought it makes the server request when the image’s src is first set.

]]>
By: James https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-507 Thu, 22 Jan 2009 08:21:14 +0000 https://j11y.io/?p=446#comment-507 Thanks all!

Yep, Thomas, you’re correct, although I made my own little modification which prevents any server requests from being made. I suppose I shouldn’t have called it “my magical method”; I guess I’m just a fan of alliteration! 😉

]]>
By: Thomas Milburn https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-506 Thu, 22 Jan 2009 08:05:43 +0000 https://j11y.io/?p=446#comment-506 I presume James got the idea from here.

]]>
By: Brenelz https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-505 Wed, 21 Jan 2009 23:25:12 +0000 https://j11y.io/?p=446#comment-505 Wow… neat trick James!

How did you find this one out?

]]>
By: Joseph McCann https://j11y.io/snippets/getting-a-fully-qualified-url/#comment-504 Wed, 21 Jan 2009 23:06:50 +0000 https://j11y.io/?p=446#comment-504 Very interesting…well done James.

]]>