PDA

View Full Version : Javascript URL



thatguythatsme
August 3rd, 2007, 09:38 AM
Is there a way to grab the url of a page. Not just the full url line 'window.location.href' which would equal http://www.mysite.co.uk/aboutme... I want to just get the /about me section without the full address.?

Thanks
David

kBisk
August 3rd, 2007, 03:13 PM
Well it would be done by getting the full window location and then splitting the string at "/".

deltawing1
August 3rd, 2007, 08:26 PM
<html>
<body>
<script type="text/javascript">
var addy="www.microsoft.com/coolstuff/games/flightsim/coolplanes.html (http://www.microsoft.com/coolstuff/games/flightsim/coolplanes.html)";
var myArray = addy.split("/");
var answer = myArray[myArray.length-1];
document.write(answer);
</script>
</body>
</html>

The above script was not tested! But I think the concept is there. You basically get the last item in the array, which is what you're looking for.