使用jQuery Mobile在Phongap的ChildBrowser中打开所有外部链接 [英] Opening all external links in Phongap's ChildBrowser using jQuery Mobile

查看:111
本文介绍了使用jQuery Mobile在Phongap的ChildBrowser中打开所有外部链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery Mobile& Phonegap,并具有以下代码以使用ChildBrowser打开某个div中的所有外部链接:

I'm using jQuery Mobile & Phonegap, and have the following code to open all external links in a certain div with the ChildBrowser:

$('.someDIV a').live('click', function() { 
    var thisUrl = $(this).attr('href'); 
    PhoneGap.exec("ChildBrowserCommand.showWebPage", thisUrl); 
    return false; 
}); 

由于某种原因,页面在加载到子浏览器中时也会在后台加载,就好像没有"return false"一样.

For some reason, while the page loads in the childbrowser, it also loads in the background, as if there's no "return false".

我找到了一种解决方法,将链接的href属性的值设置为#",并使用url的标题,如下所示:并相应地更新jQuery代码,但这是动态生成我的链接的问题,并且title属性中没有网址.

I've found a workaround by giving the link's href attribute a value of "#", and using the title for the url like this: And updating the jQuery code accordingly, but this is a problem where my links are dynamically generated, and I can't have the url in the title attribute.

任何想法如何解决这个问题?

Any ideas how to solve this?

推荐答案

您似乎也需要阻止它传播:

It looks like you need to stop it from propagating too:

.live

.bind('click', function(e) { 
e.stopImmediatePropagation();
...
})

http://api.jquery.com/event.stopImmediatePropagation/

以上没有任何工作的机会.我复制了第一行...对不起

The above had no chance of working. I copied the first line... Sorry

您必须使用.bind才能覆盖默认的链接操作.

You have to use .bind to be able to override the default link action.

我一般不使用.live(),如果可以使用bind进行同样的操作,我建议不要使用它. .live()有点神奇,有时会产生后果.

I don't use .live() in general and I suggest not using it if there's a way to do the same with bind. .live() is a bit magic and it sometimes has consequences.

这篇关于使用jQuery Mobile在Phongap的ChildBrowser中打开所有外部链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆