Chopping up document.URL: is there an easier way?
Hey guys - this is the short description of my question:
My URL contains two query strings and (optionally) an anchor link.
let's say for example it is http://www.ilovescript.ing/test/urlparsing.html?from=1&to=10#article2
Within the scope of this question I want to end up with a var that is just from=1&to=10
so I came up with these lines, but I am curious if it can done with less variables and code!
- var TheUrl = document.URL; // set current url as TheUrl
var ChoppedUrl = TheUrl.split('?', 2); // split at question mark
var ChoppedUrl2 = ChoppedUrl[1]; // get part after question mark
var ChoppedUrl3 = ChoppedUrl2.split('#', 2); // split at dash
var ChoppedUrl4 = ChoppedUrl3[0]; // get part before dash