简体   繁体   中英

href's onclick breaks after other href is clicked

I am using jquery mobile in a cordova app.

I have multiple links (jquery mobile buttons), some of which follow a normal href link, others call some code in onclick .

When pressing my buttons making use of onclick , they work for multiple presses . I can press them multiple times, each time envoking the code.

However, when I press on of my buttons with a normal href link, my buttons making use of onclick seems to break. The moment I press a button following a normal href link, my other onclick buttons stop working.

It is worth noting that my buttons making use of onclick , also NEVER shows the "pressed" animation that jquery mobile adds when clicked. The normal href buttons ALWAYS shows the "pressed" animation when clicked.

My links all navigate to outside of the app, either activating an intent, or navigating to an external website using InAppBrowser . The normal href buttons always works.

I have tried to reload the page in place when a button is clicked, but this does not work.

 $("#ctel").on('click', function (e) {

      $.mobile.changePage("#businessCard");

 });

My links:

<a href="tel:x" id="ctel" class="ui-btn ui-icon-phone ui-btn-inline ui-btn-icon-notext ui-corner-all"></a>
<a href="mailto:x" id="cmail" class="ui-btn ui-icon-mail ui-btn-inline ui-btn-icon-notext ui-corner-all"></a>
<a href="#" id="cbookings" class="ui-btn ui-icon-calendar ui-btn-inline ui-btn-icon-notext ui-corner-all" onclick="window.open('link', '_system');"></a>
<a href="#" id="cwebsite" class="ui-btn ui-icon-home ui-btn-inline ui-btn-icon-notext ui-corner-all" onclick="window.open('link', '_system');"></a>

As @Sithys was suggesting, I actually did have an error not relating directly to the jquery mobile buttons. I was re-writing my url's to point to another stats url, from which it then redirected to the appropriate url.

It seems some of the intents did not like this redirect, and probably caused an undesired effect/error somewhere in the android/cordova eco system. I removed the stats url, and by implication the redirect to the intent, and all is working as it should.

Strangely, I did however test this in Ripple emulator, and there it works perfectly fine with the stats tracking url and redirect.

I ended up doing a manual ajax post to track my clicks, and just activated the intents as per normal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM