Posted By

svenito on 06/25/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

beneberle


get base path


 / Published in: JavaScript
 

  1. var baseURL = "";
  2.  
  3. $(document).ready(function(){
  4. if (baseURL != "") {
  5. return;
  6. }
  7. getDocumentBasePath();
  8.  
  9. });
  10.  
  11. function getDocumentBasePath() {
  12. documentBasePath = document.location.href;
  13. if (documentBasePath.indexOf('?') != -1)
  14. documentBasePath = documentBasePath.substring(0, documentBasePath.indexOf('?'));
  15. if (documentBasePath.indexOf('index.php') == -1){
  16. baseURL = documentBasePath+"/index.php";
  17. } else {
  18. if (documentBasePath.lastIndexOf('index.php/') == -1) {
  19. baseURL = documentBasePath;
  20. } else {
  21. documentBasePath = documentBasePath.substring(0, documentBasePath.lastIndexOf('/'));
  22. baseURL = documentBasePath;
  23. }
  24. }
  25. }

Report this snippet  

You need to login to post a comment.