Tag Archives: url

URL parameters in Javascript

I wanted a piece of code in pure javascript ( no framework required ) that could extract the parameters in the query string part of an URL.

I wanted it to be able to extract the parameters in this format name[key]=value  like they are used in php applications.

I found a piece of code on some other blogs or forum posts but it didn't work as I expected so here is my take on this.

  1.  
  2. function get_url_params(){
  3. var _GET = {};
  4. var s = location.search.replace( /^\?|#.*$/g, '' );
  5. if( s ) {
  6. var qsParts = s.split('&');
  7. var i, nv;
  8. for (i = 0; i < qsParts.length; i++) {
  9. var nv = qsParts[i].split('=');
  10. var n=decodeURIComponent(nv[0]);
  11. var v=decodeURIComponent(nv[1]);
  12. var k=n.split(/[\[\]\.]/);
  13. if(k.length){
  14. if(_GET[k[0]])_GET[k[0]][k[1]]=v;
  15. else {
  16. if(parseInt(k[1])==k[1])
  17. _GET[k[0]]=[];
  18. else _GET[k[0]]={};
  19. _GET[k[0]][k[1]]=v;
  20. }
  21. }else _GET[n] = v;
  22. }
  23. }
  24. return _GET;
  25. }
  26.  

This function one limitation: It doesn't work with multidimensional arrays. It's probably not hard to modify it to work like that but I only needed it to work with single dimension arrays.

Where’s the xml sitemap?

Someone contacted me through the contact form to ask me where is the xml sitemap generated by the xml sitemap module for pligg .

If he would have read my first post about this module I think he would have eventually figured out where it is but since that first post was written a long time ago let me answer that question in this post.

I will do this in a post instead of answering privately because maybe there are others that might run into the same problem and I hate answering the same question over and over.

The module doesn't generate a sitemap but a sitemap index ( that's basically just a list of sitemaps in xml ) and unless you're using cache the module will generate it every time someone goes to the sitemap's URL.

If you're not using friendly urls for sitemaps then the url to the sitemap will be :
http://yourpliggsite.com/module.php?module=xml_sitemaps_show_sitemap
If you want to use friendly urls for the sitemap you will have to configure it as described here

Last time I checked ( when I first created the module ) ask.com could not be pinged unless your sitemap url looked like a static url or/and was ending in .xml and this is why I created the module with this choice in mind. If you don't care about pinging ask.com or if ask.com changed it's policy ( can anyone check this ? ) then you don't need friendly urls for sitemaps.

For the future I would appreciate if such questions would be asked in the comments instead of private contact. I prefer the comments for answering questions about my posts or the code in my posts because this way others can benefit from my answers or others can contribute.

The contact form would be for private matters like asking for consultancy , business proposals or others that don't fit into the comments.