PDA

View Full Version : Need help with getting page name..



ShadowIce
06-03-2009, 03:59 PM
Hi all, I've been doing some research on url names. The problem is, I need this code to return like say "index.php", it would return "index". But idk where I went wrong..

Anyway..

The code:


<script>
var sPage;
var sPath = window.location.pathname;
//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
//var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
if(sPath.substring(sPath.lastIndexOf('.') + 1)){
sPage=sPath.split("",3);
}
sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
alert(sPage);
</script>

ANY help is GREATLY appreciated! :)

~SI~

ShadowIce
06-03-2009, 09:36 PM
Here, this might help explain what I need a bit better. since no 1 seems to want to answer my question....


http://codingforums.com/showthread.php?t=168020

forum_amnesiac
06-04-2009, 06:14 AM
I've just tried your code, in files named showurl.htm and showurl.php, and in both types it returned the full file name, ie showurl.html or showurl.php.

I tried a couple of the suggestions given by the other forum and with those I just got 'showurl'.

I tested this using IE7, so I'm not sure if this is a browser issue.

molendijk
06-04-2009, 06:01 PM
<script type="text/javascript">
alert(document.URL.substring(document.URL.lastIndexOf('/')+1,document.URL.length-4));
</script>

Arie Molendijk.