ChildBrowser onLocationChange 不起作用

发布于 2025-01-01 05:33:44 字数 1395 浏览 1 评论 0原文

基本上我在 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 等。

Basically I am using ChildBrowser on iOS, it works almost perfectly. The problem is the onLocationChange, onClose and onOpenExternal don't work and for the life of me I can't figure out why.

Any help would be much appreciated

<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>

I have tried window.plugins.childBrowser.onLocationChange ect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多孤肩上扛 2025-01-08 05:33:44

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

take out the root.onlocationChange, no need to have that.

无所谓啦 2025-01-08 05:33:44

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

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

Encapsulate the locChanged, onCloseBrowser, onOpenExternal into a main function to make correct calls because childbrowser when it´s opened doesn't have the scope of locChanged
for example:

var facebook = function() {
    locChanged = funciton() {
        //your code here
    }
    return {
        "init": init,
        "locChanged": locChanged,
        "onCloseBrowser": onCloseBrowser,
        "onOpenExternal": onOpenExternal
    }
}();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文