Opening all external links in Phongap's ChildBrowser using jQuery Mobile

半世苍凉 提交于 2019-12-12 19:35:10

问题


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; 
}); 

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

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?


回答1:


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

.live

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

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

[edit]

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

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

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.



来源:https://stackoverflow.com/questions/5101665/opening-all-external-links-in-phongaps-childbrowser-using-jquery-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!