hello. i need a JS that collects variable from link at begining of page loading for example look at these codes: suppose this is the link: http://my-domain/path/file.php?id=13 Code (markup): & this is file.php code <html> <head> <title>my page</title> <script type="text/javascript"> var theVariable = [B][COLOR="Red"]// I need this codes[/COLOR][/B] </script> </head> <body> [COLOR="Red"]// some body code, i'll write it myself[/COLOR] </body> </html> Code (markup): so, when this page load, see id=13...i mean variable "id" value is 13 i want some JS code that collect that value (here 13) in "theVariable" plz help me
erm, if this is a php file then why not just... <html> <head> <title>my page</title> <script type="text/javascript"> var theVariable = "<?=$_GET['id']?>"; </script> </head> PHP:
why the hell not? <script type="text/javascript">var theVariable = "<?=$_GET['id']?>";</script> <script type="text/javascript" src="myfile.js"></script> PHP: and in myfile you can totally reference theVariable.
You'll have to use the location object for that: var theVariable = location.search.match(/id=([\d]+)/)[1] Code (markup):
i dont know why but its not working everytime... this is great...very simple trick but didnt hit my head its working fine