Please help a java idiot. I have a function that i would like to be called based on the url. something like if url= http://mysite.com/sub/pagename/show then call the function. Pagename will vary. Can anyone help me code that?
It's not exactly clear to me what you want, but this would use RegEx and check for similiar criteria you speicified, where pagename can vary and contains letters and numbers var v = new RegExp(); v.compile("^http://www.mysite.com/sub/[A-Za-z0-9]+/show$"); if (!v.test($url_to_check)) { foo(); } Code (markup):
$_SERVER['REQUEST_URI']=Your page, inluding folders. I think this includes get variables? $_SERVER['SCRIPT_NAME']=Same deal, but probably without get variables. Quick function(untested) to extract out the script's name, without get variables function getScriptName() { $s=$_SERVER['SCRIPT_NAME']; $spl=explode("/",$s); $s=$spl[sizeof($spl)-1]; $spl=explode("?",$s); return(trim($spl[0])); }
Oops! My bad. I think in PHP, and saw it in the new posts, and just kinda assumed.... I shall now quietly retreat...
this should return you the current document : <script type="text/javascript"> <!-- // try this (add http:// if needed) function getHost() { var url = window.location.href; var nohttp = url.split('//')[1]; var hostPort = nohttp.split('/')[0] alert (hostPort) } getHost(); </script> Code (markup):