1

I manually have a constructed web page in a string for displaying in WebBrowser control (part of code)

    ie.Document.clear

        str = "<!DOCTYPE html>" & vbCrLf _
            & "<html>" & vbCrLf _
            & "<head>" 

& vbCrLf _
        & "<script src=""http://code.jquery.com/jquery-1.10.2.js""></script>" & vbCrLf _

            & "<script>" & vbCrLf _
     & "$(function() {" _
    & "$( ""#dialog"" ).dialog();" _
    & "});" _
    & "</script>" & vbCrLf _
            & "</head><body>" & vbCrLf _

ie.Document.write str
ie.Document.Close

After many hours of investigation, I finally concluded that JQuery external *.js script isn't loaded at time that WB parser reaches the dialog() function. Even I put the file locally (with local path) isn't loaded.

The IE error is "The value of property $ is null or undefined...".

The HTML (constructed) code is OK because I did a very simple test. I saved the WB page source via right click -> page source, I saved locally as *.htm and back in MSACCESS, I use navigate WB's method

ie.Navigate "file:///V:/...file.htm"

And this is working just fine.

So the question is why

ie.Document.write str  -> not working
ie.Navigate -> works

I need the first method since I use WinHTTP to make a request, take some real page, parse and finally display in WB.

Of course, I could manipulate emulation from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION which btw works but this will fall into several problems on other machines where I cannot have access to registry.

Thanks in advance,

3
  • Please post the final rendered HTML verbatim, as well as look at what your browser's F12 network tools say is happening. Commented Mar 29, 2015 at 22:41
  • Since loading the file locally works, you could write out the content to a file in the user's Temp folder and load it from there. Commented Mar 30, 2015 at 1:51
  • @Tim Williams nice, I was about to write to TMP and load from there, thanks! Commented Mar 30, 2015 at 5:32

2 Answers 2

2

Got It! I noticed accidentally that right click refresh will load the JS :) Since I spent many hours to dig, here is the trick in case someone will need:

ie.Silent = True           ' <-- supress any JS warnins
ie.Document.clear
ie.Document.write str
ie.Refresh    ' <-- this will load the JQuery just fine

I really don't understant WTF Microsoft still use default ancient IE in emulated stuff including it's own products like Office?!

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

1 Comment

Thanks!! I was able to get it working after reviewing your answer. You should accept your own answer.
0

After testing the OP's answer I concluded that refreshing the WebBrowser does indeed load JQuery.

A few notes:

  • "" is required
  • WebBrowser.Document.Clear isn't needed
  • WebBrowser.Navigate or WebBrowser.Navigate2 can be used
  • WebBrowser.Refresh or WebBrowser.Refresh2 can be used

Test

Dim HTML As String
With CreateObject("System.Text.StringBuilder")
    .Append_3 "<!DOCTYPE html>" & vbCrLf
    .Append_3 "<HTML>" & vbCrLf
    .Append_3 "<HEAD>" & vbCrLf
    .Append_3 "<SCRIPT src=""http://code.jquery.com/jquery-1.10.2.js""></SCRIPT>" & vbCrLf
    .Append_3 "<SCRIPT>" & vbCrLf
    .Append_3 "$(function() {" & vbCrLf
    .Append_3 "$( ""#test"" ).css( ""border"", ""3px solid red"" );"
    .Append_3 "});"
    .Append_3 "</SCRIPT>" & vbCrLf
    .Append_3 "</HEAD>" & vbCrLf
    .Append_3 "<BODY>" & vbCrLf
    .Append_3 "<DIV id=""test"">Hey</DIV>"
    .Append_3 "</BODY>" & vbCrLf
    .Append_3 "</HTML>" & vbCrLf
    HTML = .ToString
End With

With WebBrowser1
    .navigate "About:Blank"
    .Silent = True
    .Document.Write HTML
    .Refresh
End With

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.