Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9054187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:37:24+00:00 2026-06-16T13:37:24+00:00

Assuming http://example.com/js/script.js fires an AJAX request against some relative URL, how do I get

  • 0

Assuming http://example.com/js/script.js fires an AJAX request against some relative URL, how do I get the absolute URL that ended up being requested?

For example, if I request image.png from http://example.com/js/script.js I’d expect to get back http://example.com/js/image.png. If, however, I requested /image.png from the same URL I’d expect to get back http://example.com/image.png.

This question is tricky for two reasons:

  1. I don’t believe it’s possible to get a script’s URL from inside it. UPDATE: I incorrectly assumed that AJAX requests are issued relative to the script location. It turns out that they are issued relative to location.href. This simplifies the situation.
  2. I don’t believe that XMLHttpRequest exposes the request URL, not to mention its absolute form.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:37:27+00:00Added an answer on June 16, 2026 at 1:37 pm

    I don’t believe it’s possible to get a script’s URL from inside it.

    For that, simply use location.href

    A quick hack to get absolute url from a relative one could be :

    function getAbsoluteURL(relative) {
        var a = document.createElement('a');
        a.href = relative;
        return a.href;
    }
    

    According to this question it could not work on Ie6 , but does it really matter ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For example, I have a huge HTML file that contains img URL: http://ex.example.com/hIh39j+ud9wr4/Uusfh.jpeg I
If I have an XML file that looks like this: <properties> <property> <picture>http://example.com/image1.jpg</picture> <picture>http://example.com/image2.jpg</picture>
With the new Diggbar, you can put http://digg.com in front of any URL that
I wish to issue the following curl request using php-curl: curl http://www.example.com/ -F file=@foo.ext
Assuming that we have: http.HandleFunc(/smth, smthPage) http.HandleFunc(/, homePage) User sees a plain 404 page
Assuming I have a page request which goes like http://localhost/accounting/products?id=234 and sometimes it goes
http://leaverou.github.com/animatable/ On this page, click a block and see the black box that appears.
Assuming that I'm on a page on a different domain (mydomain.com) and that the
Consider this example: http://jsfiddle.net/treeface/P8JbW/ HTML : <div id=test> <img src=http://ycombinator.com/images/y18.gif /> </div> CSS :
I don't understand the documentations at jScrollPane at all. http://jscrollpane.kelvinluck.com/#examples They give an example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.