Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery/JS: Get current URL parent directory

From:

http://www.site.com/example/index.html

How can I get just:

http://www.site.com/example/

And storing it into a variable using Javascript and how using jQuery also. Thanks in advance.

like image 924
Eduardo Go Avatar asked Jul 05 '13 21:07

Eduardo Go


2 Answers

The following seems to work

new URL(".", "http://example.com/folder/subfolder/file.js")
like image 197
dmail Avatar answered Oct 10 '22 14:10

dmail


http://jsfiddle.net/mXpBx/

var s1 = "http://www.site.com/example/index.html";
var s2 = s1.replace(s1.split("/").pop(),"");
like image 23
fr4nk Avatar answered Oct 10 '22 14:10

fr4nk