Javascript when using COMCONTROL mshtml

Started by mhall, August 29, 2014, 02:25:12 AM

Previous topic - Next topic

mhall

OK,

Last post of the evening, I think! :)

Is is possible/easy to use javascript and/or a javascript libary when using the mshtml control?

I have a dialog with very simple content - it's a valid HTML page, but only has a single element within the body, an image tag. I read the page template from disk and insert the path to the image I want to display. That all works great.

However, I am displaying images of varying aspect ratios and would like to dynamically resize the image and position it within the control.

I am very familiar with jQuery ... so much so that my raw javascript DOM skills have rusted quite badly, so I would prefer to use jQuery, if possible. But I get continual errors when trying to use jQuery or even basic javascript in the page. I'm running a web server here on my system ... I've tried referring to the jQuery library on the server via an http://localhost path on the server, tried an absolute path and have even tried simply pasting the entire library into a <script> tag in the page. But the jQuery global variable is never accessible. Likewise when trying to use raw Javascript  (document.getElementById()  ) and then read a property from the image I am getting errors as well.

Which leads me to wondering ... is it possible to use javascript within the page itself in an mshtml element, or is it better interacted with outside via WinBatch?

This is simply to satisfy my curiosity at the moment, I wound up with an acceptable all CSS solution for my preview scaling issue, but I'd still like to know for future reference.

Thanks!
Micheal


stanl

Just a thought:  Maybe substitute "Shell.Explorer" for "MSHTML:" as your COM control and see if you have better luck.

td

The problem could possibly be the result of on of  the obtuse Control Panel Internet Options setting.  Which one it might be? No idea.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mhall

Hi Stan,

Playing with your neat mapping script the other day is what got me to go ahead and try out the ComControl. I did try a direct swap for the Shell.Explorer control, but the script crashed when I got to document.open(), so I'm assumed that's a method that's not available for that control. (Big assumption, I did no digging to find out further). I saw in your example that you passed it a URL to open and got to thinking that perhaps the mshtml control is good for displaying straight HTML and the Shell.Explorer control is better at displaying real pages. But, again, that's just a quick look supposition.

I'll give Shell.Explorer another shot and spend a bit more time with it. Can anyone point me to some documentation on the control itself? In looking at your code Stan, I seen a lot of familiar methods, which is reassuring. I've found this in my searches: http://msdn.microsoft.com/en-us/library/hh772374%28v=vs.85%29.aspx

Regards,
Micheal

stanl

With Shell.Explorer (assuming the COM Control is named oIE - my convention)

oIE.Navigate(cURL) ;where cURL is either a page or a local .html file

oIE.Document.Write(cHTML) ;if loading html code w.out file/io

td

Quote from: mhall on August 29, 2014, 06:23:29 PM
...

I'll give Shell.Explorer another shot and spend a bit more time with it. Can anyone point me to some documentation on the control itself? In looking at your code Stan, I seen a lot of familiar methods, which is reassuring. I've found this in my searches: http://msdn.microsoft.com/en-us/library/hh772374%28v=vs.85%29.aspx

Regards,
Micheal

The WIL Type Viewer can be used to view the methods, properties and events of both the WebBrowser interface (an interface of shell.explorer) and the HTMLDocument  interface (MSHTML:).  To view the WebBrowser interface type "shell.explorer" or "internetexplorer.application" in the propid box of 'Viewer' tab then press the "Get Library" button.  Scroll down to the IWebBrowser interface and expand.   To view the HTMLDocument interface type "htmlfile" in the progid box and press the "Get Members" button.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mhall

Thanks Tony! So many cool tools. I completely forgot about the TypeViewer. Looking at it now.

~Micheal