Userscripts(JavaScripts)

xeross

Member
Joined
Feb 7, 2008
Messages
6
Programming Experience
1-3
I need to be able to use Userscripts in a vb.net application.
I think i found 2 ways you could do this but i don't know how.

1. Use opera or firefox as a component in the application and make one of them load the userscript(i don't want people to need to install Firefox/Opera though)
2. As soon as a page is loaded execute the javascript on it somehow.

Can anyone help with this ?

Thanks in advance, Xeross
 
The WebBrowser control is basically an instance of IE so, just like IE, you need to load an HTML page into it and it will execute the script the page contains. You can either call the Navigate method and specify the file location or assign a String containing the page source to the DocumentText property.
 
Ok let me explain what userscripts are :
A userscript is a script that get's executed by the webbrowser on some web pages, it runs from the users pc not from the place where the website is hosted.
 
Where did I say anything about Web site hosting? I said you could specify the location of the file. I didn't say that that file could not be local. I also said that you could assign the page source directly to the DocumentText property as a string. That couldn't possibly involve a file on a Web server because it requires an in-memory String.
 
I think you aren't explaining what you need clearly.

From what I've read of what you want, I think that jmcilhinney's idea will work fine.
 
That is a script written for GreaseMonkey, which is an addin for Firefox. They are regular Javascripts but may use objects only available in FF or provided by GM engine.
With Webbrowser control you can load and run scripts like this:
VB.NET:
Dim newElement As HtmlElement = Me.WebBrowser1.Document.CreateElement("script")
newElement.SetAttribute("type", "text/javascript")
newElement.SetAttribute("text", "function sayhi(){alert(""hi"");}")
Me.WebBrowser1.Document.GetElementsByTagName("head")(0).AppendChild(newElement)
Me.WebBrowser1.Document.InvokeScript("sayhi")
You can also add JS code in the script to automatically run code and functions when script is loaded.
 
Back
Top