Good afternoon. I have a case where I need to parse a number out of a web url and store it within a data input form.
The valid application url is this: http://<machinename>/<applicationname>
However, I need to send a URL by clicking on the button that reads something like this: http://<machinename>/<applicationname>/19305
Of course this is not a real application site, so as the application is loading, I need to parse out 19305 so it reads http://<machinename>/<applicationname>. I then need to take the parsed value, then send it to an input form so it will locate within an application.
Has anyone done this?
Ian
Solved! Go to Solution.
Ian
If you want to be able to click a button that goes to http://machine/app/19305 but really gets loaded as http://machine/app you'll need a server side piece to handle the routing. To get that question answered you may want to post on a site like Stack Overflow.
To handle if from the client side you'd want to go with the url parameter approach so when users clicked on the button they'd go to http://yourappurl?id=19305
Then you could use javascript like Paul and I posted above to get the id value from the url.
for this:
http://machinename/applicationname?n=19305
var params = {};
if (location.search) {
var parts = location.search.substring(1).split('&');
for (var i = 0; i < parts.length; i++) {
var nv = parts.split('=');
if (!nv[0]) continue;
params[nv[0]] = nv[1] || true;
}
}
var thenumber = Number(params.n);
thenumber now = 19305.
Can you use url parameters instead? So your url would be something like:
http://myserver/myapp/index.html?id=19305
The JSAPI has a helper method that makes it easy to extract the parameter from the url doing something like this:
var urlObject = urlUtils.urlToObject(url); if(urlObject.query && urlObject.query.id){ var myId = urlObject.query.id; }
And here's a link to a sample that shows this in action:
https://developers.arcgis.com/javascript/jssamples/exp_history.html
So if I click a button that goes to http://machine/app/19305 the application will actually be loaded as http://machine/app? This is what I am wanting. The http://machine/app/19305 URL is actually not a real URL, but I want to capture the data while the app is loading. I hope this makes sense.
Attached is a copy of my code.
Ian
Ian
If you want to be able to click a button that goes to http://machine/app/19305 but really gets loaded as http://machine/app you'll need a server side piece to handle the routing. To get that question answered you may want to post on a site like Stack Overflow.
To handle if from the client side you'd want to go with the url parameter approach so when users clicked on the button they'd go to http://yourappurl?id=19305
Then you could use javascript like Paul and I posted above to get the id value from the url.
Thank you for the responses! I actually looked at the sample from ESRI and that works extremely well. I referred to the sample and now have a web application set up that does exactly what I need it to. Starting to like AMD more and more
Great news Ian. Glad you have your app up and running.