2

Alloy を使用して WebView から Titanium に通信できませんか? 過去の Ti.App.fireEvent() では動作していたようですが、新しい Alloy プロジェクトでは動作しません。はい、これらのドキュメントを読みましたが、古くなっているようです: https://wiki.appcelerator.org/display/guides/Communication+Between+WebViews+and+Titanium Alloy を使用する場合、app.js はありませんファイル - Alloy.js ファイルのみ。誰かが ALLOY でこれが機能する例を持っているなら、これは素晴らしいことです! これが私が試したことです。

webview.html

  <html>
  <head>
    <script type="text/javascript">
    function fire(e){
      alert("Before Ti.App.fireEvent");
      Ti.App.fireEvent("fromWebview",{});
      alert("After Ti.App.fireEvent");
    }
    </script>
  </head>
  <body>
  <a href="#" onClick="fire()">Click this link to execute the fire() function</a>
  </body>
</html>

index.xml

<Alloy>
    <Window id="w_history">
            <WebView id="webview" url="/webview.html" />
    </Window>
</Alloy>

index.js

Ti.App.addEventListener('fromWebview',function(e){
  alert("Clicked from Web");
});

$.w_history.open();

f Ti.App.fireEvent が発火する前にコードのみのダイ アラートを実行しましたが、その後のアラートは発火しませんか? これは、Ti.App.fireEvent が実行されておらず、関数が壊れていることを意味していると思いますか?

私は一日中これにこだわっています!どんな助けでも大歓迎です!ありがとう

4

2 に答える 2