ChildBrowser onLocationChange 不起作用
基本上我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
取出root.onlocationChange,不需要那个。
take out the root.onlocationChange, no need to have that.
将
locChanged
、onCloseBrowser
、onOpenExternal
封装到主函数中,以便在childbrowser
打开时进行正确调用没有 locChanged 的范围例如:
Encapsulate the
locChanged
,onCloseBrowser
,onOpenExternal
into a main function to make correct calls becausechildbrowser
when it´s opened doesn't have the scope oflocChanged
for example: