我使用以下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:
页面加载的电话就好了)
有人可以给我建议,我该如何避免这种冲突? 谢谢!
答案 0 :(得分: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;
}
相关帖子: