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
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
See this related answer: http://stackoverflow.com/questions/1418050/string-strip-for-javascript
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.
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