Posted By

oxisound on 02/18/08


Tagged

get url page getURL current referencie


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

SpinZ
korzhik


getURL: Current Page Reference


 / Published in: JavaScript
 

(c) copyright Stephen Chapman, 1st Jan 2005. Example: alert('http://'+uri.dom+uri.path+'/folder/file.js');

  1. function getURL(uri) {
  2. uri.dir = location.href.substring(0, location.href.lastIndexOf('\/'));
  3. uri.dom = uri.dir; if (uri.dom.substr(0,7) == 'http:\/\/') uri.dom = uri.dom.substr(7);
  4. uri.path = ''; var pos = uri.dom.indexOf('\/'); if (pos > -1) {uri.path = uri.dom.substr(pos+1); uri.dom = uri.dom.substr(0,pos);}
  5. uri.page = location.href.substring(uri.dir.length+1, location.href.length+1);
  6. pos = uri.page.indexOf('?');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
  7. pos = uri.page.indexOf('#');if (pos > -1) {uri.page = uri.page.substring(0, pos);}
  8. uri.ext = ''; pos = uri.page.indexOf('.');if (pos > -1) {uri.ext =uri.page.substring(pos+1); uri.page = uri.page.substr(0,pos);}
  9. uri.file = uri.page;
  10. if (uri.ext != '') uri.file += '.' + uri.ext;
  11. if (uri.file == '') uri.page = 'index';
  12. uri.args = location.search.substr(1).split("?");
  13. return uri;
  14. }
  15. var uri = new Object();
  16. getURL(uri)

Report this snippet  

You need to login to post a comment.