How can I simulate a click?


#1

I’m making a demo page with an app for 3 platforms (android, ios and windows) I want to simulate the same event for 3 iframes for example, how to navigate to a page.

I’ve this website http://cordova-multiplatform-template.js.org/ and I tried to simulate clicks with jquery like
$('.simulator_ios iframe').contents().find('.tab-item').last().click() but doesn’t work.

Any suggestions?

Thanks!


#2

nothing about this??


#3

+1 I also would like to do this !!


#4

This isn’t really an ionic thing, it’s a general website thing. With no code or examples we can’t really help you. Have you tried solving it yourself?

I would 1) Log the object that you’re getting from $(’.simulator_ios iframe’).contents().find(’.tab-item’).last() to make sure it’s not null or undefined.

  1. Log that something is being clicked

  2. Handle a click event on the entire document because you can use that to determine where something was clicked and the element.

The issue is most likely that your code isn’t selecting the right element.


#5

THanks for your answer!

i know i’m reaching the right element because this works:

    document.getElementById(id).focus();

(it does put the cursor in the field… but no keyboard pops up)

However, using cordova.plugins.Keyboard.show(); to show the keyboard only brings the alphanumeric keyboard even when the input is of type ‘number’… So i thought that if I could instead provoke a ‘click’ or ‘tap/touch’ event on the input field it could bring up the right kind of keyboard, just as a real physical tap on the input field does…

So i tried :

        document.getElementById(id).click();

but it does nothing… any suggestions ??


#6

You almost have it, from what I understand the tap/click do not work the same as in a desktop. It will move the ‘cursor’ around but it won’t invoke the keyboard to come up.

The original question was wanting help by using that code in iFrames, are you doing this on the emulator or device though?

This answer on stack overflow shows that you have to do a sort of round about event set up. So when the field is clicked you have to force focus. So they bind the focus to the click event, then trigger the click event.

Side note: The input type (text/number) won’t determine the type of keyboard that shows on every platform.

That is a little bit older of a post, but it will hopefully get you in the right direction. There are quite a few resources. I wish they just used the type attribute, would have been easier.


#7

I think that is an Ionic thing… I want to test the events without changing my code :S there’s an example wit three iframes cordova-multiplatform-template.js.org