Implementation to send variables through the url (with javascript) like PHP $_GET.
I remember several times this question has been asked in this forum and I never found an appropriate answer. So today as I was reading a book I thought of sending variables through javascript from one page to the other. This is just an experiment which I thought I should share it with you so that I know what I did wrong and what I need to implement.:) Here's the script:
Code:
<html>
<head>
<title>Javascript Implementation to PHP type GET variables.</title>
<script type="text/javascript">
var url = String(window.location);
var index = url.indexOf("?");
var data = url.substr(index+1);
var splitted = data.split("=");
event = splitted[0];
act = splitted[1];
</script>
</head>
</body>
<script type="text/javascript">
if(index == -1){
document.write("Please Click One of these links: <a href='"+url+"?user=false'>Login as a Guest</a><br /><a href='"+url+"?user=true'>Login as a user</a>");
} else if(event == "user" && act == "true"){
document.write("Welcome User.");
} else {
document.write("You are a stranger!!!");
}
</script>
</body>
</html>
So what do you think guys??
EDIT: Forgot to mention it still can't catch all the url variables(for e.g this=that&multiple=variables).