Passing URL parametes from C# app to HTML page
russ@russtoolshed.net
Posted on
May 20 2015
I am implementing the affected user capability in my Xamarin Forms app. It is a hybrid app where I use a webpage as part of the registration process (subscription to an automated web based news). Does anyone have an example of the preferred way passing and consuming parameters in a HTML Page JavaScript? I have all of the user information captured in the app and would like to send it to the Web page to pre populate an email field and setup Raygun client info in that part of the app, the HTML page. The URL will be hidden form the end user as I will be running this through a webview control. I guess I could write a web service to take care of this, but, I am looking for a simple and quick solution here by just passing parms and consuming them in the HTML page. Thanks.
russ@russtoolshed.net
Posted on
May 21 2015
This works: From C#:
Using a webview control in Xamarin Forms: subscribeWebView.Source = "http://www.yoursite.com/Subscribe.html?useremail=" + UserEmail;
In Subscribe.html:
function getParameterByName(name) { name = name.replace(/[[]/, "\[").replace(/[]]/, "\]"); var regex = new RegExp("[\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/+/g, " ")); }
var useremail= getParameterByName('useremail');