2017-04-01 36 views
9

我有一個網絡的服務在這一我已經加入的AndroidAndroid的網絡視圖錯誤I /鉻:[INFO:控制檯(1)]「未捕獲的ReferenceError:

條形碼讀取器因此具有的幫助JavaScript的我從網上查看打電話給我的條碼閱讀器因此對於I followed this

,並設計了服務器端... 我已經給這個

在JavaScript的

function mybarcd() { 
      MyApp.mybarcdt(); 
     } 

    function actfromAnd(msg){ 
      document.getElementById("brcd").value = msg; 
     } 


    at HTML/PHP 

    <div class="data"> 
      <input id="brcd" type="text" value=""/> 
      <button type="button" onClick="mybarcd()">SCAN</button> 
    </div> 

在Android上側 在網頁視圖

webView.addJavascriptInterface(new WebAppInterface(this), "MyApp"); 

和新的JS接口

@JavascriptInterface 
    public void mybarcdt() { 

       IntentIntegrator intentIntegrator = new IntentIntegrator(Main_A.this); 
       intentIntegrator.setBeepEnabled(true); 
       intentIntegrator.setOrientationLocked(true); 
       intentIntegrator.setPrompt("Scan Barcode"); 
       intentIntegrator.initiateScan(); 
      } 



    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 
     if (result != null) { 
      if (result.getContents() == null) { 
       Log.d("ScanActivity", "Cancelled scan"); 
       Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show(); 

      } else { 

       Log.d("ScanActivity", "Scanned"); 

       String bcval = result.getContents(); 
       if (android.os.Build.VERSION.SDK_INT < 19) { 
        webView.loadUrl("javascript:actfromAnd(\""+bcval+"\")"); 
       }else{ 
        webView.evaluateJavascript("javascript:actfromAnd(\""+bcval+"\")", null); 
       } 
       System.out.println("javascript:actfromAnd(\""+bcval+"\")"); 

      } 
     } else 
      super.onActivityResult(requestCode, resultCode, data); 
    } 

我的問題是,它在SI做工精細與Js的Html/PHP文件在同一頁或單獨的頁面我已經測試了它的掃描和更新輸入框中的值...

但它不工作,因爲我在一個webview中使用多個頁面或框架... 其缺少的JS值...如何形成服務器其開幕掃描儀在點擊...但掃描後的價值是沒有傳遞到輸入框與JS我得到這個錯誤.....

I/chromium: [INFO:CONSOLE(1)] "Uncaught ReferenceError: actfromAnd is not defined", source: (1) 

更新

1)I HAVA在側與JS嘗試這種在靜態網頁,PHP/HTM大號
頁 2)我也有同樣想在一個靜態頁面與JS單獨的頁面
在上述兩個條件其工作的罰款

但在我的網絡服務,我已經給它在成功運行相同的JS文件靜態頁面我有一個單獨的JS文件我的Web服務和靜態頁面其靜態工作正常,但不工作在我的web服務生活..如何加載JS因爲點擊它從JS和它的開幕相機但掃描後響應它不會網絡輸入

據我所知,我得到錯誤,因爲...

In my Live Page I have a MainMenu Inside that menu when I select a application its loading in iframe So my Android Activity responce after scanning Is pinging to that Mainmenu page But for menu there is no Js function named actfromAnd So I am getting Error...

在這裏,我不能給特定頁面(iframe)因爲根據菜單的URL它將改變我能給的也只有登錄或MainMenu的鏈接directly.but沒有爲特定的頁面裏面的菜單

可以任何人建議我這種...

+0

哪裏是actfrom和方法寫的?如果它在PHP中是腳本寫入輸出頁面? –

+0

'actfromAnd'是用JS和Android編寫的兩種形式android我將用JS發送我的條形碼輸出到'actfromAndroid',但它的工作原理如何,但是......它不適用於我的情況,請檢查我的更新問題...由於'iframe'沒有響應...我的應用程序發送數據到菜單頁面不是'iframe頁面'所以我得到錯誤 – MLN

+1

嘗試與父母。<< yourfunction >>名稱如果您使用iframe –

回答

1

你父菜單具有添加在網絡服務這個腳本您iframeiframes

<script> 
function actfromAnd(msg){ 
window.frames['yourExactframe'].document.getElementById("brcd").value = msg; 
} 
</script> 

如果你是在一個以上的幀使用相同然後聲明你的框架名全球

我試過你的代碼工作很好...在我的例子框架希望它適合你

很好的問題....

+0

謝謝這個示例代碼幫助我.... **'window.frames ['yourExactframe']。** **它的工作......只有一行.... – MLN

0
  • 當頁面加載

    mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { webview.loadUrl("javascript:myFunction()"); } });

  • 的代碼會被執行,會發現你的JavaScript功能,您應該執行JavaScript。你現在的做法不會等待。

+0

感謝您的響應用戶@ Harshil Kulkarni .......我已經在onPageFinished中添加了這個,但沒有響應仍然是同一個問題...因爲登錄後我需要選擇菜單在菜單中我的web服務在那裏對於特定的模塊只有這個Java腳本...所以它不工作... – MLN

+0

好吧,對不起,我會稍後刪除我的帖子。 –

+0

沒有問題..但這可能有助於某些人如此保持答案,如果你得到新的更新它....感謝... – MLN

相關問題