How do you enable JavaScript with TWebBrowser(actually SHDocVW)?

I have a simple browser application designed in Delphi, and I use the ActiveX control SHDocVw. I navigated around and I encountered several errors when using a site that has Flash! I started using the EmbeddedWB (from www.euromind.com) and I still recieve errors - mainly a crash when the Flash animation stops and a JavaScript call shakes the screen (visit Disney.com - there is a Flash presentation of "The Incredibles" and then the JavaScript function that is called afterwards does a screen shake).

I guess this is a browser-side feature that can be trapped or caught. I want to know what to do on this one - other than disabling the Flash and script capability... I know I can do that as a last resort. I just want to trap the issue and dispay the animation as it should be displayed. I know there must be a way!

Please supply any code snippets...

I checked on things like this...

WebBrowser1.OleObject.Document.ParentWindow.ExecScript(...parameters...)

But this would require a great deal of parsing for certain JavaScript calls (at least I think it would).


Thanks for your help -

-John
arterberryAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ginsonicConnect With a Mentor Commented:
Hmmm! What IE use you ? And what OS ?

My fullWEB browser work perfect for specified link.
0
 
ginsonicCommented:
Not sure if I understand, but you can call a Java script with:

procedure ExecuteScript(doc:IHTMLDocument2;script:string;language:string);
var
 win: IHTMLWindow2;
 Olelanguage: Olevariant;
begin
 if doc <> nil then
 begin
   try
     win := doc.parentWindow;
     if win <> nil then
     begin
       try
         Olelanguage := language;
         win.execScript(script, Olelanguage);
       finally
         win := nil;
       end;
     end;
   finally
     doc := nil;
   end;
 end;
end;

ExecuteScript(WebBrowser1.Document as
HTMLDocument2,'MyJava()','JavaScript');
0
 
ginsonicCommented:
Add:

uses
  MSHTML_TLB, SHDocVw, ShellAPI;
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
arterberryAuthor Commented:
Thank you for your help, ginsonic -

I like this - but I have one quick review question...when I use this function -

ExecuteScript(WebBrowser1.Document as HTMLDocument2,'MyJava( )','JavaScript');

What if I do not know the name of the script - for example - 'MyJava( )'?
Do I have to hard-code the name of script strings in the ExecuteScript call each time?

In other words, I want to create an open-ended support for JavaScript with my browser application. In the event that my browser application encounters JavaScript - I would like for it to just run it.

Is that possible?

Again, thank you ginsonic.
0
 
ginsonicCommented:
I tested with my application fulWEB browser and look that all is perfect for me on disney.com. Can you download my browser from www.construiesc.ro/fullWEB and test it ?

I can't get any error for specified address and I use EmbeddedWB component, too.
0
 
arterberryAuthor Commented:
Thanks ginsonic -

I just checked (with your browser (VERY NICE!!!))!

I saw that Disney removed the "shake" example ... so I found this instead...

http://www.javascriptkit.com/javatutors/advwin3.shtml

And I scrolled down and clicked on the "Shake Window" button (with your browser). And your browser worked flawlessly.

My browser does fail when I go and shake the window.

I will add this to my code -

ExecuteScript(WebBrowser1.Document as HTMLDocument2,'MyJava( )','JavaScript');

along with the function you wrote. I will just use the generic 'MyJava( )' string and run this link

http://www.javascriptkit.com/javatutors/advwin3.shtml

- to see what will happen.

 
0
 
arterberryAuthor Commented:
Hello ginsonic,

I have – well – attempted to use this procedure. I have provided the code here. I designed this in Delphi 5, and I am using the browser wrapper from Euromind. I have included my code here – in full, below.  When I go to the link (http://www.javascriptkit.com/javatutors/advwin3.shtml), and scroll down – and then select the “Shake Window” button – my web browser goes blank. I look forward to your response and again – thank you for your help. I will provide points once this thing is working!


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  OleCtrls, SHDocVw_TLB, StdCtrls, MSHTML_TLB, ShellAPI;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button1: TButton;
    WebBrowser1: TWebBrowser;
    Scriptlet1: TScriptlet;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ExecuteScript(doc:IHTMLDocument2;script:string;language:string);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
     WebBrowser1.Navigate(Edit1.Text);
end;

procedure TForm1.ExecuteScript(doc:IHTMLDocument2;script:string;language:string);
var
 win: IHTMLWindow2;
 Olelanguage: Olevariant;
begin
 if doc <> nil then
 begin
   try
     win := doc.parentWindow;
     if win <> nil then
     begin
       try
         Olelanguage := language;
         win.execScript(script, Olelanguage);
       finally
         win := nil;
       end;
     end;
   finally
     doc := nil;
   end;
 end;
end;


end.
0
 
arterberryAuthor Commented:
Hello ginsonic,
I am using Windows XP (Service Pack 2) and IE 6.
0
 
arterberryAuthor Commented:
Is the code okay?
I know that I have no clue as to how to implement the procedure into my code. Could you run through and compile the code and apply some magic to this crazy problem.

Thanks ginsonic
0
 
ginsonicCommented:
I don't use any special code into my browser to use the java. And how you can see work perfect for me. I will make some test on weekend (sorry no time untill then) to see what happening and what make my browser to work and your no.

At this moment my opinion is that you use some code that affect the normal function of the EmbeddedWB.

P.S. I suggest to update your IE to the last version and use EventSinkImp from
http://www.euromind.com/iedelphi/gettingstarted/usefulTools.htm
to install again your component.
0
 
ginsonicCommented:
The single solution that I can figure out is to set your WindowState to wsMaximized and the border form to bsNone. In this case work perfect. Else :(

Of course the browser must be set to alClient.

Tested and work perfect. Don't know is is a wrapper or OS problem !?!?
0
 
ginsonicCommented:
no comments?
0
All Courses

From novice to tech pro — start learning today.