[英]javascript username password https login issue for windows phone 8
I am a newbie coming from IOS and Android and trying to replicate a feature in those apps where I use a username and password that is saved in preferences (isolatedstorage) and inject it into the javascript of the https web page. 我是来自IOS和Android的新手,并尝试在这些应用程序中复制功能,在这些应用程序中,我使用保存在首选项(隔离存储)中的用户名和密码并将其注入到https网页的javascript中。 From a previous question I asked before I now understand that I can not use System.Windows.Forms as that is for W8Desktop and I am targeting windows phone 8.
从之前我问过的一个问题开始,我现在才知道我不能使用System.Windows.Forms,因为它是针对W8Desktop的,并且我的目标是Windows Phone 8。
In android I did the following: 在android中,我执行了以下操作:
view.loadUrl(“javascript:document.getElementById(‘Login1_UserName’).value=’”+userName+”‘;javascript:document.getElementById(‘Login1_Password’).value = ‘”+password+”‘;”);
view.loadUrl(“javascript:document.getElementById(‘Login1_LoginButton’).click();”);
and I am trying to do it in Visual Studio 2012 but its not working. 我正在尝试在Visual Studio 2012中执行此操作,但无法正常工作。 Here is my code:
这是我的代码:
Browser.Navigate(new Uri(mainUrl, UriKind.Absolute));
Browser.InvokeScript(“eval”, new string[] { “document.getElementById(‘Login1_UserName’).value = ‘”+username+”‘ , document.getElementById(‘Login1_Password’).value = ‘”+password+”‘;”});
Browser.InvokeScript(“eval”, new string[] { “document.getElementById(‘Login1_LoginButton’).click();”});
But it just wont work. 但这只是行不通的。 So my questions are two:
所以我的问题是两个:
Many thanks for any pointers you may be able to give to help. 非常感谢您可以提供帮助的任何指示。
I have a solution now, but still need to know how to implement it. 我现在有一个解决方案,但仍然需要知道如何实现。
Here is the correct code to inject javascript into the form. 这是将javascript注入表单的正确代码。
browser.InvokeScript("eval", "document.getElementById('Login1_UserName').value = '" + username + "';");
browser.InvokeScript("eval", ("document.getElementById('Login1_Password').value = '" + password + "';"));
browser.InvokeScript("eval", string.Format("document.getElementById('Login1_LoginButton').click();"));
The issue I had was that I was not allowing the page to finish loading before running the script. 我遇到的问题是,在运行脚本之前,我不允许页面完成加载。 I have tried a few things but to no aval so I will keep digging and edit once I have it solved.
我已经尝试了一些方法,但没有尝试过,因此一旦解决,我将继续进行挖掘和编辑。
Hope this helps someone else. 希望这对其他人有帮助。
JUST REMEMBER YOU CAN NOT USE browser.document as you see in some solutions as it wont work on windows phone. 请记住,您不能使用在某些解决方案中看到的browser.document,因为它将无法在Windows Phone上使用。 Happy to be corrected as I am a newbie, but that trail cost me too many hours.
我是新手,很高兴得到纠正,但是那条路花了我太多时间。 You need to use Invokescript for windows phone code.
您需要将Invokescript用于Windows Phone代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.