HTTP-EQUIV="REFRESH" conflict with window.location

HTTP-EQUIV="REFRESH" conflict with window.location = url

本文关键字:quot window location with conflict HTTP-EQUIV REFRESH      更新时间:2023-09-26

我使用以下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分析那个页面,我得到的是:

获取网址 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>

获取网址 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"

(问题取决于我的 JavaScript,如果我删除stringByEvaluatingJavaScriptFromString:页面加载正常的调用)

有人可以给我建议,我怎样才能避免这种冲突?谢谢!

问题已解决:

我已经在我的脚本中替换了 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/