I was thinking over a way to send variables from one page to another using javascript, but without the use of cookies; like in server side scripts with the variables embedded in the URL by using the GET method. The advantages of such a program are obvious:
Then, I thought of the link fragment indentifier as a potential implementation of this idea. This is because:
The only disadvantage of such an implementation is that the original purpose of the fragment identifier is defeated. However, in respect to its new usage, this disadvantage is negligible.
So I started working on this project, and in less than 5 minutes I created a prosaic but working script of this idea. I decided to call it "Hypertext Transreceiver and Processor" or "HTP", since is sounds similar to "HTTP". However, the "processor" part of it is not quite true; so I am looking for a more accurate full form for the acronym "HTP" (which I do not want to change). I am also looking for ideas to streamline my script. Feel free to post them here. This is my script till now:
- Users can bookmark pages with the javascript variables they desire, e.g. bookmark words in a online dictionary for quick reference.
- It does not require creation of cookies and hence saves cookie space, as each domain can set upto a maximum of 20 cookies.
Then, I thought of the link fragment indentifier as a potential implementation of this idea. This is because:
- It loads the HTML page as it normally would, even though it may not find an anchor with the fragment identifier name or an element with that id. So the browser happily ignores the fragment identifier.
- A web page can reference another page in any domain. This overcomes the problem of cookies, which can only be accessed in a particular domain. So you can send variables to any web page on the internet.
The only disadvantage of such an implementation is that the original purpose of the fragment identifier is defeated. However, in respect to its new usage, this disadvantage is negligible.
So I started working on this project, and in less than 5 minutes I created a prosaic but working script of this idea. I decided to call it "Hypertext Transreceiver and Processor" or "HTP", since is sounds similar to "HTTP". However, the "processor" part of it is not quite true; so I am looking for a more accurate full form for the acronym "HTP" (which I do not want to change). I am also looking for ideas to streamline my script. Feel free to post them here. This is my script till now:
| Code: |
| var HTP=
{ action:"", setVariables:[], setVariable:function(name,value) { if(typeof name!="string"||typeof value!="string")return false; var invalidSequences=new Array("#","=","&&"); for(var i=0;i<invalidSequences.length;i++)if(name.indexOf(invalidSequences[i])>=0||value.indexOf(invalidSequences[i])>=0)return false; this.setVariables.push(name+"="+value); return true; }, submit:function() { if(this.setVariables.length==0)return false; window.location.href=this.action+"#"+this.setVariables.join("&&"); if(this.action=="")window.location.reload(true); return true; }, getVariables:[], getVariable:function(name) { if(typeof name!="string")return false; name=name+"="; for(var i=0;i<this.getVariables.length;i++) { var variable=this.getVariables[i]; if(variable.indexOf(name)==0)return variable.substring(name.length,variable.length); } return null; }, initialize:function() { if(window.location.href.toString().indexOf("#")>0) { var variables=window.location.href.toString().split("#")[1].split("&&"); for(var i=0;i<variables.length;i++)this.getVariables.push(variables[i]); } } } |
