Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios window.location.href在phonegap中不工作_Ios_Cordova - Fatal编程技术网

Ios window.location.href在phonegap中不工作

Ios window.location.href在phonegap中不工作,ios,cordova,Ios,Cordova,我想重定向到Phonegap中的另一个页面 我已经用javascript编写了以下代码,但没有重定向: window.location.href = "http://www.google.com"; 有人能告诉我为什么它不起作用吗?尝试执行以下操作: 打开您的文件Cordova.plist文件 右键单击ExternalHosts->addrow 将新添加行的字符串值设置为* 因此,您应该像这样添加新的行: Item0 String * 通常,您应该

我想重定向到Phonegap中的另一个页面

我已经用javascript编写了以下代码,但没有重定向:

window.location.href = "http://www.google.com";

有人能告诉我为什么它不起作用吗?

尝试执行以下操作:

  • 打开您的文件
    Cordova.plist
    文件

  • 右键单击
    ExternalHosts
    ->
    addrow

  • 将新添加行的
    字符串
    值设置为
    *

因此,您应该像这样添加新的行:

Item0            String          *
通常,您应该将
*
替换为要提供访问权限的外部URL(如
http://www.google.com
例如),但我使用了
*
来确保问题是否来自那里

有关更多信息,请查看在线文档的“域白名单指南”部分:


下面是一个使用
window.location.href
的简单工作示例:

<!DOCTYPE html>
<html>
    <head>               
        <script type="text/javascript" charset="utf-8">
            function init() {
                window.location.href = "http://www.google.com";
            }      
        </script>
    </head>

    <body onload="init();">
    </body>                

</html>
window.location = "http://www.google.com";

函数init(){
window.location.href=”http://www.google.com";
}      

让我知道这是否有效。

很可能是您要移动到的页面。该页面是否包含phongap.js文件等

尝试一个简单的测试:创建一个新的HTML页面,其中只包含基本元素和正文中的几个单词,这样你就知道你在那里了。将其另存为test.html。现在尝试window.location=“test.html”

如果这行得通,那么你就知道这是新的一页。
祝你好运

您是否检查了框架初始化?在尝试更改页面之前,请确保jquery和phonegap已完全加载。否则phonegap会挂断


看看这里:

使用Cordova 4对我来说很好。您可以尝试使用Google Chrome进行远程调试,并查看Javascript控制台中发生的情况吗?

尝试不使用
href

<!DOCTYPE html>
<html>
    <head>               
        <script type="text/javascript" charset="utf-8">
            function init() {
                window.location.href = "http://www.google.com";
            }      
        </script>
    </head>

    <body onload="init();">
    </body>                

</html>
window.location = "http://www.google.com";

如果您使用像
window.location
window.location.href
这样的工具,并且它在IOS或safrai中不起作用

您可以使用以下选项:

var isAndroid = !!navigator.userAgent.match(/android/ig);
        var targetUrl = 'your url';
        window.location = targetUrl;

if(!isAndroid) {
    var doc = window.document,
        ifr = doc.createElement('iframe');
    ifr.src = targetUrl;
    ifr.style.cssText = 'display:none;';
    doc.body.appendChild(ifr);
}

您必须通过配置白名单来允许在应用程序内部导航外部站点

您必须像这样使用
允许导航
标记:

Item0            String          *

仅使用window.location=”“是否可以工作可能重复。请检查document.window.location是否向白名单中添加了异常?是的,我在cordova.plist中创建了OpenAllWhitelistURLsInWebView=是,但window.location也不工作。:(…您在控制台上有任何错误吗?
警报(“hi”)
如果未注释则触发?控制台上是否有任何错误?我将使用window.location.href发布一个简单的示例…然后,您可以尝试一下,看看问题是否来自于此。好吗?请稍候…请尝试一下我刚刚发布的示例:)。我希望这对你有用:Syes你的例子对我有用。但它在我的应用程序中不起作用。你可能在某处有代码问题:S。你可以做的是用浏览器(例如:firefox)打开你的js文件,并使用控制台(或Firebug:)检查你是否没有任何synthax错误。这是cordova插件白名单的一部分,之前也必须添加。白名单插件仅适用于android,问题是关于iOS的。