NeXT5tep
NeXT5tep

Reputation: 881

How do I emulate a click on a div then fire the onclick event in webview programmatically?

I am new to JavaScript, just created a cocoa app with a webView embedded which display the gmail iPhone site. What I want to do here is to schedule a timer method, then in the timer method,emulate a click on a refresh button to fire the on click event?

enter image description here

Upvotes: 3

Views: 4767

Answers (2)

Francesco Terenzani
Francesco Terenzani

Reputation: 1391

Dom events can be fired just calling it:

The code below will fire the click event of the element with the id '#foo'

document.getElementByTagName('foo').onclick();

Upvotes: 3

Karthik
Karthik

Reputation: 824

Thats really simple, you should have written a function to do the refresh activity and just put that function inside setInterval,

Syntax: setInterval(code,millisec,lang)

where,
code - A reference to the function or the code to be executed
millisec - The intervals (in milliseconds) on how often to execute the code
lang -(Optional) JScript | VBScript | JavaScript

For Example,

function refreshIphoneStuff(){
//Your code here
}

You can call this function based on the time like the one below,

window.setInterval("refreshIphoneStuff()",1000); //This will call that function for every 1 sec.

Hope this helps!

Update:

If the page is created by you (i.e) the refresh functionality is created by you then you can attach a handler on the image like,

<img src='pathtorefreshbuttonimage/refresh.gif' onclick="refreshIphoneStuff();">

(or) if its purely from gmail side then you must use some webdeveloper tools like firebug or webdeveloper toolbar to guess which function is called on click of refresh.

Hope this will clear your issues!

Upvotes: 1

Related Questions