Opening all external links in Phongap's ChildBrowser using jQuery Mobile
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 hr开发者_StackOverflowef 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/
[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.
精彩评论