Page 1 of 1

browser "execute" script

Posted: Thu Jun 13, 2013 11:22 am
by seaniepie
Hello everyone,

I'm trying to send a keydown (the spacebar, 'n', or whatever) to the iOS browser. So I use iPhoneControlCreate to make my browser. Into this I have a URL of a page which is waiting for one of the aforementioned keys to be pressed. In this URLs html is a script called 'player.js' with an ID of 'PlayerDemo'. The code does not use the jQuery library. So somehow using JS I need to execute a script on the press of a LC button that triggers a keydown event.

I was led to some code on stackoverflow which goes like this:
http://stackoverflow.com/questions/5964 ... key-events

Code: Select all

var keyboardEvent = document.createEvent("KeyboardEvent");
var initMethod = typeof keyboardEvent.initKeyboardEvent !== 'undefined' ? "initKeyboardEvent" : "initKeyEvent";

keyboardEvent[initMethod](
                   "keydown", // event type : keydown, keyup, keypress
                    true, // bubbles
                    true, // cancelable
                    window, // viewArg: should be window
                    false, // ctrlKeyArg
                    false, // altKeyArg
                    false, // shiftKeyArg
                    false, // metaKeyArg
                    40, // keyCodeArg : unsigned long the virtual key code, else 0
                    0 // charCodeArgs : unsigned long the Unicode character associated with the depressed key, else 0
);
document.dispatchEvent(keyboardEvent);
'n' has a key code of 78, space has a key code of 32. I'm not sure what a mouseclick would be. But how do I get 'iPhoneControlSet "browsername","execute",tMyScript' to work?

Thanks in advance
Sean

225 views in 4 days and no replies. Impressive! I like asking questions that no one else knows the answer to. Helps me see I might be onto something groundbreaking. - seaniepie (added 17-06-13)

Re: browser "execute" script

Posted: Mon Jun 17, 2013 4:07 pm
by strongbow
Hi Sean

I send a JS function call to a web page inside my native browser using the method you describe. I'm just making a JS call though, like "updateLoc()" as the "myScript" parameter. And inside the web page I have a JS function defined with the same name, containing that functionality.

So my suggestion would be to make your own "myKeyDown(tKey)" function using JS inside your web page and then send that with the particular key pressed to your page to then execute.

Let me know if you have any other questions or if you need more detail.

cheers

Alan

Re: browser "execute" script

Posted: Mon Jun 17, 2013 4:33 pm
by seaniepie
Hi Alan,

Thanks for the input. The problem is that the webpage is not entirely mine. Specifically, the JavaScript. To be more specific, it's based on powerpoint that has been converted to html via iSpring Convertor. I have contacted them and they say I should be able to just target the 'document.dispatchEvent' as all keyboard and mouse events are picked up by the document as a whole rather than any other object. So, I should just be able to use 'iPhoneControlSet "browsername","execute",tMyScript' and it just work. But, alas, as yet I have been unable.

Maybe someone else has an idea.

Re: browser "execute" script

Posted: Mon Jun 17, 2013 5:58 pm
by strongbow
Hmm... could you perhaps load the URL into a local var, modify it to include your JS function, and then reload it... and then use the method I describe? Or is that not possible?

Re: browser "execute" script

Posted: Sun Jul 07, 2013 9:17 pm
by seaniepie
Well done Alan, that did it. Load the URL into a var. I know it ends with </script></body></html> so I put my function in before that and it works just fine. Thanks for your inspiration.