UWP get form in webviewer returning 'about:blank' rather than form values
We have a mobile app which shows an html page with some javascript in a webviewer.
In this page we have a form. IT looks something like:
<form method="get" action = "" id="mainform">
<input name="EXAMPLE_NAME" id"EXAMPLE_NAME" placeholder="" type="text" maxlength="35"/>
</form>
So far so good. The user is able to view this input and fill it in with data. They then press a button on the xaml page which calls a function that does:
Browser.Eval("submitMainForm()")
In the javascript on the page we have that function, which looks like:
function submitMainForm() {
var x = document.getElementById("mainForm").submit();
}
Back in the C# code we have handlers for the resulting navigation. They look like:
async void OnNavigating(object sender, WebNavigatingEventArgs e)
{
and
void OnNavigated(object sender, WebNavigatedEventArgs e)
{
This works well in iOS and Android. We get the WebNavigatingEventArgs in the handler, and the value from the field that we are showing in the webviewer (inside of mainform) are stored in there.
So, for example, e.Url in the OnNavigating and OnNavigated handlers would look something like:
"file:///storage/emulated/0/Android/data/com.example.exampleapp/files/Example.html?EXAMPLE_NAME=Test"
We parse this string to get the values we care about (Test, in this case), and all is well.
On UWP, however, things work a lot less well. On Navigating is never called at all, and the call to OnNavigated just has "about:blank" stored in its WebNavigateEventArgs url value.
Does anyone know what might be going on here, and/or have a way that I can fix it? I need a way to get the results from my call to the get form as I do in the other 2 platforms, rather than "about:blank". Ideally, I'd also like to get the OnNavigated call, but the important thing is the data.
Thanks for your assistance
xamarin webview xamarin.forms uwp
add a comment |
We have a mobile app which shows an html page with some javascript in a webviewer.
In this page we have a form. IT looks something like:
<form method="get" action = "" id="mainform">
<input name="EXAMPLE_NAME" id"EXAMPLE_NAME" placeholder="" type="text" maxlength="35"/>
</form>
So far so good. The user is able to view this input and fill it in with data. They then press a button on the xaml page which calls a function that does:
Browser.Eval("submitMainForm()")
In the javascript on the page we have that function, which looks like:
function submitMainForm() {
var x = document.getElementById("mainForm").submit();
}
Back in the C# code we have handlers for the resulting navigation. They look like:
async void OnNavigating(object sender, WebNavigatingEventArgs e)
{
and
void OnNavigated(object sender, WebNavigatedEventArgs e)
{
This works well in iOS and Android. We get the WebNavigatingEventArgs in the handler, and the value from the field that we are showing in the webviewer (inside of mainform) are stored in there.
So, for example, e.Url in the OnNavigating and OnNavigated handlers would look something like:
"file:///storage/emulated/0/Android/data/com.example.exampleapp/files/Example.html?EXAMPLE_NAME=Test"
We parse this string to get the values we care about (Test, in this case), and all is well.
On UWP, however, things work a lot less well. On Navigating is never called at all, and the call to OnNavigated just has "about:blank" stored in its WebNavigateEventArgs url value.
Does anyone know what might be going on here, and/or have a way that I can fix it? I need a way to get the results from my call to the get form as I do in the other 2 platforms, rather than "about:blank". Ideally, I'd also like to get the OnNavigated call, but the important thing is the data.
Thanks for your assistance
xamarin webview xamarin.forms uwp
You have not set theactionproperty in you code.
– Nico Zhu - MSFT
Nov 15 '18 at 8:18
add a comment |
We have a mobile app which shows an html page with some javascript in a webviewer.
In this page we have a form. IT looks something like:
<form method="get" action = "" id="mainform">
<input name="EXAMPLE_NAME" id"EXAMPLE_NAME" placeholder="" type="text" maxlength="35"/>
</form>
So far so good. The user is able to view this input and fill it in with data. They then press a button on the xaml page which calls a function that does:
Browser.Eval("submitMainForm()")
In the javascript on the page we have that function, which looks like:
function submitMainForm() {
var x = document.getElementById("mainForm").submit();
}
Back in the C# code we have handlers for the resulting navigation. They look like:
async void OnNavigating(object sender, WebNavigatingEventArgs e)
{
and
void OnNavigated(object sender, WebNavigatedEventArgs e)
{
This works well in iOS and Android. We get the WebNavigatingEventArgs in the handler, and the value from the field that we are showing in the webviewer (inside of mainform) are stored in there.
So, for example, e.Url in the OnNavigating and OnNavigated handlers would look something like:
"file:///storage/emulated/0/Android/data/com.example.exampleapp/files/Example.html?EXAMPLE_NAME=Test"
We parse this string to get the values we care about (Test, in this case), and all is well.
On UWP, however, things work a lot less well. On Navigating is never called at all, and the call to OnNavigated just has "about:blank" stored in its WebNavigateEventArgs url value.
Does anyone know what might be going on here, and/or have a way that I can fix it? I need a way to get the results from my call to the get form as I do in the other 2 platforms, rather than "about:blank". Ideally, I'd also like to get the OnNavigated call, but the important thing is the data.
Thanks for your assistance
xamarin webview xamarin.forms uwp
We have a mobile app which shows an html page with some javascript in a webviewer.
In this page we have a form. IT looks something like:
<form method="get" action = "" id="mainform">
<input name="EXAMPLE_NAME" id"EXAMPLE_NAME" placeholder="" type="text" maxlength="35"/>
</form>
So far so good. The user is able to view this input and fill it in with data. They then press a button on the xaml page which calls a function that does:
Browser.Eval("submitMainForm()")
In the javascript on the page we have that function, which looks like:
function submitMainForm() {
var x = document.getElementById("mainForm").submit();
}
Back in the C# code we have handlers for the resulting navigation. They look like:
async void OnNavigating(object sender, WebNavigatingEventArgs e)
{
and
void OnNavigated(object sender, WebNavigatedEventArgs e)
{
This works well in iOS and Android. We get the WebNavigatingEventArgs in the handler, and the value from the field that we are showing in the webviewer (inside of mainform) are stored in there.
So, for example, e.Url in the OnNavigating and OnNavigated handlers would look something like:
"file:///storage/emulated/0/Android/data/com.example.exampleapp/files/Example.html?EXAMPLE_NAME=Test"
We parse this string to get the values we care about (Test, in this case), and all is well.
On UWP, however, things work a lot less well. On Navigating is never called at all, and the call to OnNavigated just has "about:blank" stored in its WebNavigateEventArgs url value.
Does anyone know what might be going on here, and/or have a way that I can fix it? I need a way to get the results from my call to the get form as I do in the other 2 platforms, rather than "about:blank". Ideally, I'd also like to get the OnNavigated call, but the important thing is the data.
Thanks for your assistance
xamarin webview xamarin.forms uwp
xamarin webview xamarin.forms uwp
asked Nov 14 '18 at 20:44
WalterWalter
133
133
You have not set theactionproperty in you code.
– Nico Zhu - MSFT
Nov 15 '18 at 8:18
add a comment |
You have not set theactionproperty in you code.
– Nico Zhu - MSFT
Nov 15 '18 at 8:18
You have not set the
action property in you code.– Nico Zhu - MSFT
Nov 15 '18 at 8:18
You have not set the
action property in you code.– Nico Zhu - MSFT
Nov 15 '18 at 8:18
add a comment |
1 Answer
1
active
oldest
votes
For html form submitting, you need add the action url that used to received parameter. For example:
<form id="Myform" action="HomePage.html">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
When you invoke submit, the firstname lastname field will be sended to HomePage.html page. I create HomePage that Build Action is Content in native uwp project.

Please note you could not create html in forms project. Otherwise the webview could get navigate to the right url.
This is code sample please check.
Thank you for this sample. I was able to get it running and working, and it definitely shed light on my problem. In my code, when I changed action="" to action="www.google.com" or similar, I was able to get the values that I cared about in the URL of the WebNavigatedEventArgs. Unfortunately, it also pointed my browser to google, so I'm not quite set yet, but I am getting closer. I want the Url to be populated (not with "about?blank"), but I don't actually want to go anywhere. In iOS/Android the blank action accomplishes that. Do you know a way to do it in UWP?
– Walter
Nov 15 '18 at 20:32
If you do not go anywhere, you could set the action url as theindex.htmlin above scenario. In other words, using current html page url.
– Nico Zhu - MSFT
Nov 16 '18 at 2:14
Thank you, I was trying to do that and having difficulties. Ultimately I discovered that the reason that your original solution didn't work for me was that my form had so many values in it that the URL was too long. Once I shrunk the form down the error went away. I really appreciate your assistance.
– Walter
Nov 16 '18 at 20:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308441%2fuwp-get-form-in-webviewer-returning-aboutblank-rather-than-form-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For html form submitting, you need add the action url that used to received parameter. For example:
<form id="Myform" action="HomePage.html">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
When you invoke submit, the firstname lastname field will be sended to HomePage.html page. I create HomePage that Build Action is Content in native uwp project.

Please note you could not create html in forms project. Otherwise the webview could get navigate to the right url.
This is code sample please check.
Thank you for this sample. I was able to get it running and working, and it definitely shed light on my problem. In my code, when I changed action="" to action="www.google.com" or similar, I was able to get the values that I cared about in the URL of the WebNavigatedEventArgs. Unfortunately, it also pointed my browser to google, so I'm not quite set yet, but I am getting closer. I want the Url to be populated (not with "about?blank"), but I don't actually want to go anywhere. In iOS/Android the blank action accomplishes that. Do you know a way to do it in UWP?
– Walter
Nov 15 '18 at 20:32
If you do not go anywhere, you could set the action url as theindex.htmlin above scenario. In other words, using current html page url.
– Nico Zhu - MSFT
Nov 16 '18 at 2:14
Thank you, I was trying to do that and having difficulties. Ultimately I discovered that the reason that your original solution didn't work for me was that my form had so many values in it that the URL was too long. Once I shrunk the form down the error went away. I really appreciate your assistance.
– Walter
Nov 16 '18 at 20:02
add a comment |
For html form submitting, you need add the action url that used to received parameter. For example:
<form id="Myform" action="HomePage.html">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
When you invoke submit, the firstname lastname field will be sended to HomePage.html page. I create HomePage that Build Action is Content in native uwp project.

Please note you could not create html in forms project. Otherwise the webview could get navigate to the right url.
This is code sample please check.
Thank you for this sample. I was able to get it running and working, and it definitely shed light on my problem. In my code, when I changed action="" to action="www.google.com" or similar, I was able to get the values that I cared about in the URL of the WebNavigatedEventArgs. Unfortunately, it also pointed my browser to google, so I'm not quite set yet, but I am getting closer. I want the Url to be populated (not with "about?blank"), but I don't actually want to go anywhere. In iOS/Android the blank action accomplishes that. Do you know a way to do it in UWP?
– Walter
Nov 15 '18 at 20:32
If you do not go anywhere, you could set the action url as theindex.htmlin above scenario. In other words, using current html page url.
– Nico Zhu - MSFT
Nov 16 '18 at 2:14
Thank you, I was trying to do that and having difficulties. Ultimately I discovered that the reason that your original solution didn't work for me was that my form had so many values in it that the URL was too long. Once I shrunk the form down the error went away. I really appreciate your assistance.
– Walter
Nov 16 '18 at 20:02
add a comment |
For html form submitting, you need add the action url that used to received parameter. For example:
<form id="Myform" action="HomePage.html">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
When you invoke submit, the firstname lastname field will be sended to HomePage.html page. I create HomePage that Build Action is Content in native uwp project.

Please note you could not create html in forms project. Otherwise the webview could get navigate to the right url.
This is code sample please check.
For html form submitting, you need add the action url that used to received parameter. For example:
<form id="Myform" action="HomePage.html">
First name:<br>
<input type="text" name="firstname" value="Mickey">
<br>
Last name:<br>
<input type="text" name="lastname" value="Mouse">
<br><br>
<input type="submit" value="Submit">
</form>
When you invoke submit, the firstname lastname field will be sended to HomePage.html page. I create HomePage that Build Action is Content in native uwp project.

Please note you could not create html in forms project. Otherwise the webview could get navigate to the right url.
This is code sample please check.
edited Nov 15 '18 at 8:49
answered Nov 15 '18 at 8:42
Nico Zhu - MSFTNico Zhu - MSFT
9,7831421
9,7831421
Thank you for this sample. I was able to get it running and working, and it definitely shed light on my problem. In my code, when I changed action="" to action="www.google.com" or similar, I was able to get the values that I cared about in the URL of the WebNavigatedEventArgs. Unfortunately, it also pointed my browser to google, so I'm not quite set yet, but I am getting closer. I want the Url to be populated (not with "about?blank"), but I don't actually want to go anywhere. In iOS/Android the blank action accomplishes that. Do you know a way to do it in UWP?
– Walter
Nov 15 '18 at 20:32
If you do not go anywhere, you could set the action url as theindex.htmlin above scenario. In other words, using current html page url.
– Nico Zhu - MSFT
Nov 16 '18 at 2:14
Thank you, I was trying to do that and having difficulties. Ultimately I discovered that the reason that your original solution didn't work for me was that my form had so many values in it that the URL was too long. Once I shrunk the form down the error went away. I really appreciate your assistance.
– Walter
Nov 16 '18 at 20:02
add a comment |
Thank you for this sample. I was able to get it running and working, and it definitely shed light on my problem. In my code, when I changed action="" to action="www.google.com" or similar, I was able to get the values that I cared about in the URL of the WebNavigatedEventArgs. Unfortunately, it also pointed my browser to google, so I'm not quite set yet, but I am getting closer. I want the Url to be populated (not with "about?blank"), but I don't actually want to go anywhere. In iOS/Android the blank action accomplishes that. Do you know a way to do it in UWP?
– Walter
Nov 15 '18 at 20:32
If you do not go anywhere, you could set the action url as theindex.htmlin above scenario. In other words, using current html page url.
– Nico Zhu - MSFT
Nov 16 '18 at 2:14
Thank you, I was trying to do that and having difficulties. Ultimately I discovered that the reason that your original solution didn't work for me was that my form had so many values in it that the URL was too long. Once I shrunk the form down the error went away. I really appreciate your assistance.
– Walter
Nov 16 '18 at 20:02
Thank you for this sample. I was able to get it running and working, and it definitely shed light on my problem. In my code, when I changed action="" to action="www.google.com" or similar, I was able to get the values that I cared about in the URL of the WebNavigatedEventArgs. Unfortunately, it also pointed my browser to google, so I'm not quite set yet, but I am getting closer. I want the Url to be populated (not with "about?blank"), but I don't actually want to go anywhere. In iOS/Android the blank action accomplishes that. Do you know a way to do it in UWP?
– Walter
Nov 15 '18 at 20:32
Thank you for this sample. I was able to get it running and working, and it definitely shed light on my problem. In my code, when I changed action="" to action="www.google.com" or similar, I was able to get the values that I cared about in the URL of the WebNavigatedEventArgs. Unfortunately, it also pointed my browser to google, so I'm not quite set yet, but I am getting closer. I want the Url to be populated (not with "about?blank"), but I don't actually want to go anywhere. In iOS/Android the blank action accomplishes that. Do you know a way to do it in UWP?
– Walter
Nov 15 '18 at 20:32
If you do not go anywhere, you could set the action url as the
index.html in above scenario. In other words, using current html page url.– Nico Zhu - MSFT
Nov 16 '18 at 2:14
If you do not go anywhere, you could set the action url as the
index.html in above scenario. In other words, using current html page url.– Nico Zhu - MSFT
Nov 16 '18 at 2:14
Thank you, I was trying to do that and having difficulties. Ultimately I discovered that the reason that your original solution didn't work for me was that my form had so many values in it that the URL was too long. Once I shrunk the form down the error went away. I really appreciate your assistance.
– Walter
Nov 16 '18 at 20:02
Thank you, I was trying to do that and having difficulties. Ultimately I discovered that the reason that your original solution didn't work for me was that my form had so many values in it that the URL was too long. Once I shrunk the form down the error went away. I really appreciate your assistance.
– Walter
Nov 16 '18 at 20:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308441%2fuwp-get-form-in-webviewer-returning-aboutblank-rather-than-form-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You have not set the
actionproperty in you code.– Nico Zhu - MSFT
Nov 15 '18 at 8:18