简体   繁体   中英

Is there a way to trigger DOM events from a program running outside the browser?

I have my own web app running in a browser. I want to trigger DOM events from a program running outside the browser. What is the best way to setup this interaction? Is my best bet to send keystrokes to the browser and handling these in my web app?

I prefer a generic solution, but if certain browsers (eg Chrome) have a specific facilities for this, I'm also interested in finding out.

  1. To simulate events from javascript use eg the Event.simulate library .
  2. To trigger the simulation from outside the browser generically have your javascript use AJAX or COMET to poll/be notified by your external application .

You will run into tons of hassle, cross-browser problems, and security issues trying to send keystrokes from an app into the browser. I would not suggest trying it.

Your best bet would be to use something like AJAX polling or, better yet(if possible), sockets and setup your two apps to communicate with eachother via some type of service layer/API.

Check out socket.io for a nice way to do it on the web app side, the setup for your other app will depend on the language it is written in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM