I want to find out what is the file name of the page that a user is currently viewing (for e.g. the file name of the page where I am composing this query currently is newthread.php). If the file name is Edit.asp, then do something else......this is the code (this is the onLoad event function)
function getFile(){
var strURL=window.location

//since the file name will be at the end of the URL, I am using
//a negative number as the start parameter in the substr function

if(strURL.substr(-9,strURL.length)=="Edit.asp"){
//do something
}
else{
//do something else
}
}
But the above doesn't work. In fact, some of the JavaScript string functions I tried (like match, length etc.), none of them seem to work since the string has been derived using window.location. Why? Doesn't JavaScript consider the URL of a page as a string object?

Can someone please tell how do I resolve this?

_Aerospace_Eng_

05-13-2007, 09:44 AM

Does asp not have a method for getting the current uri? In php you could use
<?php echo $_SERVER['REQUEST_URI']; ?>
which would give you the current url that you are on. You should be using

var strURL=window.location.href
That should get things working though I think you should be doing this server side anyways.

Thanks rwedge, your code works exactly as what I wanted but what's wrong with the code I cited in my post? Why doesn't it work?

Thanks to Aerospace too for his suggestion but sorry to say, Aerospace, I am not fully convinced with your statement that I should be doing this server-side rather than client-side. I feel when & where one needs to use client-side programming & server-side programming entirely depends upon the application he is working on, isn't it?

Anyway thanks once again to both of you,

Regards,

Arpan

_Aerospace_Eng_

05-13-2007, 06:53 PM

Thanks rwedge, your code works exactly as what I wanted but what's wrong with the code I cited in my post? Why doesn't it work?

Thanks to Aerospace too for his suggestion but sorry to say, Aerospace, I am not fully convinced with your statement that I should be doing this server-side rather than client-side. I feel when & where one needs to use client-side programming & server-side programming entirely depends upon the application he is working on, isn't it?

Anyway thanks once again to both of you,

Regards,

Arpan

Thats true but you didn't quite tell us what you were working on so how can we know? :rolleyes:

If you weren't too busy trying to say I was wrong you would have noticed why your original script wasn't working. Reread my post again.