0

次の JavaScript を使用して、UIWebView で「ページの読み込み」イベントを処理します。

(function() {
if (typeof Browser == "undefined") {
    Browser = {};
}
var onWindowLoaded = function() {
    Browser.commands.sendCommand("page-loaded");
};

if (document.readyState === "complete") {
    onWindowLoaded();
}
else {
    window.addEventListener('loaded', function(event) {
                            onWindowLoaded();
                            });
}
})();

私はそれをロードしますstringByEvaluatingJavaScriptFromString:

sendCommand 関数呼び出しwindow.location = url;(イベント処理の可能性を与える特定のスキームを持つ URL)

そのため、1 ページを除いてすべて問題ありません: online.rsb.ru

UIWebView空白のページが表示されます

そのページをcurlで分析し始めたところ、次のことがわかりました。

URL online.rsb.ru を取得します

HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Fri, 13 Sep 2013 08:34:32 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://online.rsb.ru//

HTTP/1.1 200 OK
Server: nginx
Date: Fri, 13 Sep 2013 08:34:33 GMT
Content-Type: text/html
Content-Length: 125
Last-Modified: Tue, 29 Jun 2010 06:59:42 GMT
Connection: keep-alive
Set-Cookie: i=wkMdtFIyzhljiGI7BEXfAg==; expires=Sat, 13-Sep-14 08:34:33 GMT; domain=online.rsb.ru; path=/
P3P: policyref="/w3c/p3p.xml", CP="CUR ADM OUR NOR STA NID"
Accept-Ranges: bytes

<html>
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url=https://online.rsb.ru/hb/">
<title></title>
</head>
</body>
</html>

URL https://online.rsb.ru/hb/を取得します

HTTP/1.1 200 OK
Server: nginx
Date: Fri, 13 Sep 2013 08:36:18 GMT
Content-Type: text/html
Connection: keep-alive
Last-Modified: Wed, 11 Sep 2013 12:50:56 GMT
Accept-Ranges: bytes
Content-Length: 152
Set-Cookie: i=wkMdulIyzoJJM3O1BB1nAg==; expires=Sat, 13-Sep-14 08:36:18 GMT; domain=online.rsb.ru; path=/
P3P: policyref="/w3c/p3p.xml", CP="CUR ADM OUR NOR STA NID"

<html>
 <head>
  <script type="text/javascript">

 window.location = "faces/system/login/rslogin.jsp?credit=false"

 </script>
 </head>
</html>

そのため、JavaScript が次のコード行と競合する可能性があることがわかりました。

<meta HTTP-EQUIV="REFRESH" content="0; url=https://online.rsb.ru/hb/">

または

window.location = "faces/system/login/rslogin.jsp?credit=false"

stringByEvaluatingJavaScriptFromString:(問題は、ロードされたページの呼び出しを削除した場合、JavaScriptに依存します)

どうすればその衝突を避けることができますか? ありがとう!

4

1 に答える 1

0

問題は解決しました:

window.location = url; の実行を置き換えました。次のコードを使用して私のスクリプトで

 function sendURLToUIWebView(url) {
    var iframe = document.createElement("IFRAME");
    iframe.setAttribute("src", url);
    document.documentElement.appendChild(iframe);
    iframe.parentNode.removeChild(iframe);
    iframe = null;
 }

関連記事:

JavascriptからObjective-Cを呼び出す方法は?

http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript/

于 2013-09-13T13:50:16.437 に答える