2013-10-14 73 views
0

我是來自IOS和Android的新手,並試圖複製這些應用程序中的功能,我使用的用戶名和密碼保存在首選項(isolatedstorage)中並將其注入https網頁的javascript。從previous question I asked之前,我現在明白了,我不能使用System.Windows.Forms的,因爲這是對W8Desktop,我瞄準的Windows Phone 8javascript用戶名密碼https登錄問題的Windows Phone 8

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();」); 

和我我試圖在Visual Studio 2012中做,但它不工作。這是我的代碼:

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();」}); 

但它只是不會工作。所以我的問題有兩個:

  1. 如果我想創建一個小的腳本,我認爲被稱爲EVAL,做我添加了一個資源文件到我的項目或將其添加爲代碼在我的MainPage.xaml中塊。 CS?如果是這樣如何?
  2. 如果我這樣做,是否有我的語法問題?

非常感謝您可能提供幫助的任何指針。

+0

嗨,夥計們,仍然需要解決這個問題,有人會通過這個問題,並有一些想法,我做錯了什麼。 – timv

回答

0

我現在有一個解決方案,但仍需要知道如何實現它。

以下是將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();")); 

我遇到的問題是我不允許頁面在運行腳本之前完成加載。我已經嘗試了一些東西,但沒有評論,所以我會繼續挖掘和編輯,一旦我解決了。

希望這可以幫助別人。

只要記住,你不能使用browser.document,因爲你在某些解決方案中看到它不會在windows phone上工作。由於我是一個新手,很高興能夠糾正,但是這種線索花費我太多時間。您需要使用Invokescript for windows手機代碼。

+0

好的,我已經檢查了每個可能的方法爲webbrowser和每次我嘗試和加載頁面,然後等待它加載之前注入JavaScript,我收到一個錯誤。因此,在與服務器chap交談之後,我們正在修改它並使用用戶名和密碼進行POST。但是,如果你只需要在已經加載的頁面上注入JavaScript,那麼這肯定會起作用。 – timv