Extracting the Directory of the Current Document : Location « Window Browser « JavaScript DHTML






Extracting the Directory of the Current Document

   

<html> 

<head> 
<title>Extract pathname</title> 
<script type="text/javascript"> 
function getDirPath(URL) { 
    var result = unescape(URL.substring(0,(URL.lastIndexOf("/")) + 1)); 
    return result; 
} 

function showDirPath(URL) { 
    alert(getDirPath(URL)); 
} 
</script> 
</head> 
<body> 
<form> 
<input type="button" value="URL" onclick="showDirPath(window.location.href)" /> 
</form> 
</body> 
</html> 

   
    
    
  








Related examples in the same category

1.Location property
2.Methods and Properties of the Location Object
3.A Document with Anchors
4.Jump to a new location