我使用以下 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 给我处理事件的可能性)
所以一切都很好,除了一页: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>
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"
(问题取决于我的javascript,如果我删除stringByEvaluatingJavaScriptFromString:
加载页面的调用很好)
任何人都可以给我建议,我怎样才能避免这种冲突?谢谢!