最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin9PV0评论

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!

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far