Author Topic: Javascript when using COMCONTROL mshtml  (Read 4586 times)

mhall

  • Jr. Member
  • **
  • Posts: 82
Javascript when using COMCONTROL mshtml
« on: August 29, 2014, 02:25:12 am »
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

  • Pundit
  • *****
  • Posts: 796
Re: Javascript when using COMCONTROL mshtml
« Reply #1 on: August 29, 2014, 03:31:43 am »
Just a thought:  Maybe substitute "Shell.Explorer" for "MSHTML:" as your COM control and see if you have better luck.

td

  • Tech Support
  • *****
  • Posts: 2618
    • WinBatch
Re: Javascript when using COMCONTROL mshtml
« Reply #2 on: August 29, 2014, 11:07:57 am »
The problem could possibly be the result of on of  the obtuse Control Panel Internet Options setting.  Which one it might be? No idea.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


mhall

  • Jr. Member
  • **
  • Posts: 82
Re: Javascript when using COMCONTROL mshtml
« Reply #3 on: August 29, 2014, 06:23:29 pm »
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

  • Pundit
  • *****
  • Posts: 796
Re: Javascript when using COMCONTROL mshtml
« Reply #4 on: August 31, 2014, 01:57:29 pm »
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

  • Tech Support
  • *****
  • Posts: 2618
    • WinBatch
Re: Javascript when using COMCONTROL mshtml
« Reply #5 on: September 02, 2014, 08:29:37 am »
...

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.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


mhall

  • Jr. Member
  • **
  • Posts: 82
Re: Javascript when using COMCONTROL mshtml
« Reply #6 on: September 02, 2014, 05:45:38 pm »
Thanks Tony! So many cool tools. I completely forgot about the TypeViewer. Looking at it now.

~Micheal