Javascript - Return value of current page name?

Soldato
Joined
18 Oct 2002
Posts
3,245
Location
melbourne
Hi folks,

How can I get javascript to return the current filename of the web page?

Hi have three pages and I want to run a script depending on what the current page is.

Example:

IF pagename = index.php?catId=1 THEN something
IF pagename = index.php?catId=2 THEN something else

I can't do this in PHP, it has to be javascript.

I'd appreciate any pointers.

Thanks.
 
I've found something which should do the trick

Code:
<script language="JavaScript">
<!--
// Create variable is_input to see if there is a ? in the url
var is_input = document.URL.indexOf('?');

// Check the position of the ? in the url
if (is_input != -1)
{ 
// Create variable from ? in the url to the end of the string
addr_str = document.URL.substring(is_input+1, document.URL.length);

// Loop through the url and write out values found
// or a line break to seperate values by the &
for (count = 0; count < addr_str.length; count++) 
{

if (addr_str.charAt(count) == "&") 
// Write a line break for each & found
{document.write ("<br>");}

else 
// Write the part of the url 
{document.write (addr_str.charAt(count));}

}}

// If there is no ? in the url state no values found
else
{document.write("No values detected");}

-->
</script>
 
Back
Top Bottom