views:

187

answers:

4

hi all,

i'm accessing the stylesheet collection like this:

var css = document.styleSheets[0];

it returns eg. http://www.mydomain.com/css/main.css

question: how can i strip the domain name to just get /css/main.css ?

thx

A: 

See this related answer: http://stackoverflow.com/questions/1418050/string-strip-for-javascript

Jason Hall
A: 
css = css.replace('http://www.mydomain.com', '');
Erikk Ross
A: 

How about:

css = document.styleSheets[0];
cssAry = css.split('/');

domain = cssAry[2];
path = '/' + cssAry[3] + '/' + cssAry[4];

This technically gives you your domain and path.

FallenRayne
A: 

This regular expression should do the trick. It will replace any domain name found with an empty string. Also supports https://

//css is currently equal to http://www.mydomain.com/css/main.css    
css = css.replace(/https?:\/\/[^\/]+/i, "");

This will return /css/main.css

Erikk Ross