We face similar kind of issue, we have single web resource as data inputs for different fields. Each field has different properties and based on that web resource behavior should change. Previously it completely handled by parameters and once “getQueryStringParameters” become obsolete we have to move to some other solution.
We follow following approach and it will reduce our amount of code change.
- Get the current window URL
- Using “this.URL” can retrieve current url of the web resource without accessing window object.
- Set Parameters in form
- In current situation we defined field name as parameter to distinguish what the field current web resource is referring to
- Decode url and remove data component from the url
- Then use regex based function to extract query string (function taken after google search :) ).
if (this != null && this != "undefined")
{
var decodedUrl = decodeURIComponent(this.URL);
decodedUrl = decodedUrl.replace("data=",'');
var parameterValue = getQueryString("FieldName", url);
}
function getQueryString ( field, url ) {
var href = url ? url : window.location.href;
var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
var string = reg.exec(href);
return string ? string[1] : null;
};
{
var decodedUrl = decodeURIComponent(this.URL);
decodedUrl = decodedUrl.replace("data=",'');
var parameterValue = getQueryString("FieldName", url);
}
function getQueryString ( field, url ) {
var href = url ? url : window.location.href;
var reg = new RegExp( '[?&]' + field + '=([^&#]*)', 'i' );
var string = reg.exec(href);
return string ? string[1] : null;
};
No comments:
Post a Comment