views:

80

answers:

3

There is a onmousedown event on a webpage. I want to be able to have this event called from my app and have the WebBrowser object move to that page. How can I achieve this?

+2  A: 

Long story short, you can't do this. This is because the javascript is a client side technology and to accomplish what javascript does on your client you're going to have to pretend to be a client: you'll need to rebuild the entire document object model and execute the javascript that way.

You can reference this ticket where I tried solving a similar issue (calling javascript from within a PHP script): http://stackoverflow.com/questions/3221466/can-a-php-proxy-script-call-javascript-functions-like-click

Maybe if you explain the problem domain a little more, you'll discover that you don't even need the javascript all-together! What are you trying to accomplish and why is the javascript required? Good luck!

gnucom
I've figured out an alternate solution but this one would be much easier. I am the client, I have a Webbrowser object in a windows form, so shouldn't I be able to fake a mouse click? I also found this as a solution http://www.gamedev.net/community/forums/topic.asp?topic_id=321029 but it seems very very sloppy.
Pieces
You can't fake a button click but you can post/get data to wherever the button would send data to if you clicked it.
gnucom
what about this http://www.megasolutions.net/cSharp/Invoking-Javascript-Functions-from-an-Instance-of-Internet-Explorer-69881.aspx#[email protected] I haven't had time to test it out but it looks promising
Pieces
A: 

The WebBrowser.Document property gives you an HtmlDocument object, which has an InvokeScript method. I have used this before to execute JavaScript from a WebBrowser control. Frankly, it's an atrociously messy way to get something done, but it has worked for me. Could that be of use to you, maybe?

Dan Tao
Ok, how would I point it to a specific mousedown event, there are multiple ones per page.
Pieces
A: 

gnucom's right.

Perhaps not the solution you are looking for: http://watir.com/examples/
It's Ruby based and but you could have your app interact with that perhaps...

NinjaCat