Wednesday, May 31, 2006

JS querystring params when ! is the command delimiter

I faced a problem receiving the querystring params using only JS code.
Scratching the web I found examples of JS functions which rely on document.location.search to retrieve the querystring, then parsing it into oject.property=value

This solution works well on standard URL (which Domino generates by default):
myserver.com/db.nsf/docUNID?OpenDocument¶m1=value1

This is because the document.location.search would return everything after the question mark, meaning OpenDocument¶m1=value1

But what we can do when the Domino generated URL is:
myserver.com/db.nsf/docUNID!OpenDocument¶m1=value1 ?

This change can be performed server-wide by setting a parameter into the server document, then all generated URL will change the question mark with the exclamation mark. And in this case, document.location.search would be empty :)

My solution was something like this:

if(document.location.search=="") {
if (document.location.href.indexOf('!') != -1) qryString = document.location.href.substring (document.location.href.indexOf('!')) ;
} else {
qryString = document.location.search ;
}

meaning that if location.search is empty, I search for the first ! into the location.href and assume everything after is the querystring to be searched for required parameters. Not sure if this is the best approach, though ...
Post a Comment

Disclaimer: The information in this weblog is provided "AS IS" with no warranties whatsoever, and confers no rights to any institution/person/organization. These are my personal thoughts and ideas. When I am inspired by others I give credit, I do not assume other's work and efforts. This site is NOT supported, approved, blessed etc. by Lotus Software and/or IBM Corporation.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 License.