How can code in a JavaScript file get the file's URL?

Posted by dalbaeb on Stack Overflow See other posts from Stack Overflow or by dalbaeb
Published on 2009-08-14T17:45:01Z Indexed on 2010/06/15 19:42 UTC
Read the original article Hit count: 161

Filed under:
|
|
|

I need to dynamically load a CSS stylesheet into a page that's on a different domain. How can I get the complete URL of the JS file to use in the href attribute of the stylesheet?

For instance, here is the structure:

http://bla.com/js/script.js

http://bla.com/css/style.css

I want to dynamically load the stylesheet into a page http://boo.net/index.html. The problem is, I don't know the bla.com bit in advance, just the fact that the stylesheet is in ../css/ relative to the JS file.

The script is, of course, included on index.html. jQuery's fine too.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery