on 03-02-2014 4:06 PM
Hi,
I have a URL. Example:
datalink.html?param1=1¶m2=2¶m3=3
The URL points to a .HTML with a SAPUI5 view placed in the body content. In the .HMTL I also include some .js files. Within a .js file I am trying to get the parameters of the URL, using:
$.request.parameters.get("param1"')
The view displays OK however viewing the browser console I see a runtime error indicating "request" is undefined. All I'm trying to do is retrieve the URL parameters, I have searched SCN, google and a quick scan of the SAPUI5 developer guide without joy. I really must be missing a trick.
Note I am not trying to get URL parameters from within an XSJS service (where above jQuery works fine). It is from within pure SAPUI5 (or rather .JS files included in the HTML, or as an alternative within the view controller.js).
Many thanks.
Jon-Paul.
Try this code:
var complete_url = window.location.href;
var pieces = complete_url.split("?");
var params = pieces[1].split("&");
$.each( params, function( key, value ) {
var param_value = value.split("=");
console.log( key + ": " + value + " | " + param_value[1] );
});
References:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, I'll give that a try first thing tomorrow.
Just to add, the .html detailed above is embedded within an iframe of a html control in a parent view, so hoping window.location.href in child.html refers to this child rather than parent.html.
I would have thought there would have been a sap.ui.core or sap.ui.common function for this "bread and butter" requirement, hmmm.
The SAPUI5 library does provide a method.
var sValue = jQuery.sap.getUriParameters().get("myUriParam");
Regards,
Jason
The modern way would be:
sap.ui.require(["sap/base/util/UriParameters"], function(UriParameters) {
var sParam = UriParameters.fromQuery(window.location.search).get("param1");
});@see: https://sapui5.hana.ondemand.com/#/api/module:sap/base/util/UriParameters
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As tobiassorn85's solution is deprecated again, here's the current solution via the web standard class 'URLSearchParams' (not UI5 specific):
let searchParams = new URLSearchParams(window.location.search);
let param1 = searchParams.get("param1");See deprecation notice at https://sapui5.hana.ondemand.com/#/api/module:sap/base/util/UriParameters.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This message was moderated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jon,
I have created the Application project and deploy in the SAP HANA cloud Platform and its working fine.
I have some Input Fields that i want to fill using URL parameters.
https://myloginpXXXXXXXXtrial.hanatrial.ondemand.com/myui2/index.html?&Field1=Valu1&Field2=Valu2
I have created the Java Application in that 3 different files
1) Viewname.view.js
2) Viewname.controller.js
3) Index.html
I have declare thies 2 fields under the Viename.view.js
How to Fill these 2 fields from URL parameters values.
Please suggest me where i can write code and what ?
Many Thanks,
Mithun
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Both methods tested and work, including the parameters passed with a HTML href in an iframe child of a parent page. Many thanks gentlemen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 3 | |
| 3 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.