PDA

View Full Version : How to ger Url parameters



alexanderHs
19 Aug 2011, 6:23 PM
How can get a parameter from the url, i mean if have
page1.html#token=12345
i need to get the token from the url, in sencha how it is?

skirtle
22 Aug 2011, 4:07 PM
I don't think there's anything in ExtJS to do that. Isn't it just this?


var hash = location.hash;

You can then parse it however you want.

vdan
23 Aug 2011, 4:45 AM
You could do something like:

var value = Ext.Object.fromQueryString(location.search.substring(1)).token;
to get the value of token in page1.html?token=12345

By the way, I would recommend using "?" rather than "#" because the latter is used for anchors in HTML pages.

skirtle
23 Aug 2011, 4:00 PM
By the way, I would recommend using "?" rather than "#" because the latter is used for anchors in HTML pages.

I think this is an oversimplification. As long as you understand the implications there is nothing wrong with using the # style for parameters that are interpreted solely clientside. Take, for example, the ExtJS documentation. It uses # rather than ?.

Without knowing the OP's use case it is impossible to judge which is better. You may well be right, he may want ? instead of #. However, it is misleading to imply they are interchangeable. In many cases there isn't a choice.

vdan
24 Aug 2011, 1:28 AM
1- it is not an oversimplification; it is a fact
2- I have not said this is how it MUST be done. I said "recommend". I am sure AlexanderHS is smart enough to judge if it applies to its own project.