admin管理员组

文章数量:1434916

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?

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?

Share Improve this question edited Mar 7, 2020 at 6:26 Cœur 38.8k25 gold badges206 silver badges279 bronze badges asked Apr 18, 2011 at 9:47 NeXT5tepNeXT5tep 8811 gold badge11 silver badges24 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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();

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!

本文标签: