2013-06-27 6 views
1

Windows Phone 7.5 PhoneGap 응용 프로그램을 개발 중입니다. C# 뒤에있는 코드에서 JavaScript 함수를 호출해야했습니다. 내 MainPage.xaml.cs는 다음과 같습니다.C# WebBrowser InvokeScript에서 오류가 발생했습니다.

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using System.IO; 
using System.Windows.Media.Imaging; 
using System.Windows.Resources; 



namespace MFMA 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     WebBrowser webBrowser = new WebBrowser(); 

     // Constructor 
     public MainPage() 
     { 
      InitializeComponent(); 
      this.CordovaView.Loaded += CordovaView_Loaded; 
     } 

     private void CordovaView_Loaded(object sender, RoutedEventArgs e) 
     { 
      this.CordovaView.Loaded -= CordovaView_Loaded; 
      // first time load will have an animation 
      Storyboard _storyBoard = new Storyboard(); 
      DoubleAnimation animation = new DoubleAnimation() 
      { 
       From = 0, 
       Duration = TimeSpan.FromSeconds(0.6), 
       To = 90 
      }; 
      Storyboard.SetTarget(animation, SplashProjector); 
      Storyboard.SetTargetProperty(animation, new PropertyPath("RotationY")); 
      _storyBoard.Children.Add(animation); 
      _storyBoard.Begin(); 
      _storyBoard.Completed += Splash_Completed; 
     } 

     void Splash_Completed(object sender, EventArgs e) 
     { 
      (sender as Storyboard).Completed -= Splash_Completed; 
      LayoutRoot.Children.Remove(SplashImage); 
     } 

     private void OnClearCookies(object sender, EventArgs e) 
     { 
      this.webBrowser.IsScriptEnabled = true; 
      this.webBrowser.InvokeScript("clearCookies"); 




     } 
    } 
} 

다음은 index.html입니다.

<!DOCTYPE html> 
<html> 
    <head> 

     <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1,initial-scale=1"> 
     <title>MFMA</title> 
     <link rel="stylesheet" href="css/jquery.mobile-1.3.1.css" /> 
     <link rel="stylesheet" href="css/jquery.mobile.structure-1.3.1.css" /> 

     <Script type="text/javascript" src="js/jquery-2.0.0.js"></script> 
     <script type="text/javascript" src="js/jquery.mobile-1.3.1.js"></script> 
     <script type="text/javascript" src="cordova-2.4.0.js"></script> 
     <script type="text/javascript" src="js/index.js"></script> 

    </head> 
    <body> 
     <div data-role="page" id="interfacePage" class="page-bg" style="background: rgb(64,150,194) url(Icons/background_mobile.png) no-repeat center center; 
    background-position: 0% 90%;background-size:100%; -webkit-background-size: cover; -moz-background-size: cover; 
    -o-background-size: cover; background-size: cover;background-attachment:fixed"> 
      <div data-role="content" > 
      </div> 
     </div> 
     <div class="app"> 
      <h1>Apache Cordova</h1> 
      <div id="deviceready" class="blink"> 
       <p class="event listening">Connecting to Device</p> 
       <p class="event received">Device is Ready</p> 
      </div> 
     </div> 
     <script type="text/javascript"> 
      app.initialize(); 
      document.addEventListener("deviceready", onDeviceReady, false); 
      function onDeviceReady() { 

       console.log('start!!!!!!!!!!!!!!!!!!!!!!!!!!'); 
       var url; 
       if (typeof (window.localStorage) == 'undefined') { 
        console.log('local storage not defined'); 
       } 
       if (typeof (window.localStorage) != 'undefined') { 
        console.log('getting item'); 
        url = window.localStorage.getItem("url"); 
        console.log('saved URL is ' + url); 
       } 
       //var url = getCookie("url"); 
       if (url != null && url != "") { 
        window.location.href = 'http://' + url; 
       } else { 
        window.location.href = 'index1.html'; 
       } 
      } 

      function clearCookies() { 
       //console.log("success!!!!!!!!!!!!!!!"); 
       window.localStorage.removeItem('url'); 
      } 

     </script> 
    </body> 
</html> 

"An unknown error has occurred. Error: 80020006."이 문제를 해결하는 방법을 알고 있습니다. 이미 포럼 및 스택 오버플로를 거쳤습니다. 나는 해결책을 얻을 수 없었다.

+0

이 같은 오류를받을 수 있나요 호출 할 수 있습니다

this.webBrowser.InvokeScript("clearCookies", new string[]{}); 

처럼 빈 매개 변수를 사용할 수 있나요? – HMR

+0

@HMR 예 동일한 오류가 발생합니다. –

+0

이 문제를 재현하는 최소한의 HTML 페이지를 표시 할 수 있습니까? –

답변

2

경우에, 당신은 당신이 직접 제거하거나 CONSOLE.LOG을 주석 경우

this.webBrowser.InvokeScript("eval", 
new string[] { "window.localStorage.removeItem('url'); " }); 
+0

이 시도했습니다 .CordovaView.Browser.InvokeScript ("eval", new string [] { "window.localStorage.clear();"})); 오류가 사라졌습니다. 그러나 local.storage.clear()는 localstorage를 지우지 않습니다. –

관련 문제