1

i want to add a javascript File or Function to vb.net application web browser. i am using this function:

    Dim mScript As HtmlElement
    Dim mHead As HtmlElementCollection
    mHead = Browser1.Document.GetElementsByTagName("head")

    With Browser1
        mScript = .Document.CreateElement("script")
        mScript.SetAttribute("type", "text/javascript")
        mScript.SetAttribute("src", SoftwareROOT & "\plugin.js")

        .Document.Body.AppendChild(mScript)
        .Document.InvokeScript("script_load")
    End With

when i execute this function, it creates a new element at the bottom of page successfully. but the function .Document.InvokeScript("script_load") is not working..

Update:

JS File is here:

function script_load(){ alert('Hi from Script'); }

script_load();

2 Answers 2

1

You need to wait for it to load, and that will take at least a little time. Instead, just run the script_load() function directly and immediately in your JavaScript; it won't make any difference.

Sign up to request clarification or add additional context in comments.

10 Comments

Browser loads a Page.. when loading is compleate.. it adds a script file.. then try to invoke function.. here is it fails. script file is successfully added.. but didn't invoked.
@extremerose71: I believe I realize how it works. Put the line script_load(); at the end of plugin.js and it should work. Are you paying attention?
i already tried this.. js file's code is now at the post.. check it.
@extremerose71: What's the value of SOFTWARE_ROOT? Try using a forward slash (/plugin.js) instead, too.
SOFTWARE_Root is the current directory of Software.. currently it is like "F:\VB2008\new_project".. i recently told you that javascript file is successfully included. i checked this manualy.. but the problem is The function of VB.NET "Browser1.Document.InvokeScript("script_load")" is not working...
|
0
Public Sub InjectScript(Script As String)
    WebBrowser1.Document.InvokeScript("eval", New Object() {Script})
End Sub
InjectScript(My.Computer.FileSystem.ReadAllText(Environment.CurrentDirectory & "\Plugin.js".ToString))

put your js file in same root

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.