子浏览器onLocationChanged不起作用

时间:2012-01-29 18:15:09

标签: ios cordova phonegap-plugins

基本上我在iOS上使用ChildBrowser,它几乎完美无缺。问题是onLocationChange,onClose和onOpenExternal不起作用,对于我的生活,我无法弄清楚原因。

非常感谢任何帮助

<script type="text/javascript" charset="utf-8">
    var cb;
    function onBodyLoad()
    {
        document.addEventListener("deviceready",onDeviceReady,false);
    }
    /* PhoneGap has been initialized and is ready to roll */
    function onDeviceReady()
    {
        console.log("Device Ready");
        cb = ChildBrowser.install();
    }

    function openChildBrowser(url)
    {
        console.log("New Url"+url);
        try {
            cb.showWebPage(url);
            cb.onLocationChange = function(loc){ root.locChanged(loc); };
            cb.onClose = function(){root.onCloseBrowser()};
            cb.onOpenExternal = function(){root.onOpenExternal();};
        }
        catch (err)
        {
            alert(err);
        }
    }

    function onCloseBrowser()
    {
        console.log("closed");
        alert("In index.html child browser closed");
    }

    function locChanged(loc)
    {
        console.log("new loc:"+loc);
        childBrowser.close();
        alert("In index.html new loc = " + loc);
    }

    function onOpenExternal()
    {
        console.log("new loc:");
        alert("In index.html onOpenExternal");
    }
</script>

我试过window.plugins.childBrowser.onLocationChange等。

2 个答案:

答案 0 :(得分:0)

取出root.onlocationChanged,不需要那个。

答案 1 :(得分:0)

locChangedonCloseBrowseronOpenExternal封装到主函数中以进行正确的调用,因为childbrowser在打开时没有locChanged的范围1}} 例如:

var facebook = function() {
    locChanged = funciton() {
        //your code here
    }
    return {
        "init": init,
        "locChanged": locChanged,
        "onCloseBrowser": onCloseBrowser,
        "onOpenExternal": onOpenExternal
    }
}();