Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-22
13
Medium Priority
?
3,289 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:arterberry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
13 Comments
 
LVL 9

Expert Comment

by:ginsonic
ID: 12387210
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
 
LVL 9

Expert Comment

by:ginsonic
ID: 12387215
Add:

uses
  MSHTML_TLB, SHDocVw, ShellAPI;
0
 

Author Comment

by:arterberry
ID: 12401330
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Expert Comment

by:ginsonic
ID: 12402334
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
 

Author Comment

by:arterberry
ID: 12403960
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
 

Author Comment

by:arterberry
ID: 12407419
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
 
LVL 9

Accepted Solution

by:
ginsonic earned 1500 total points
ID: 12407512
Hmmm! What IE use you ? And what OS ?

My fullWEB browser work perfect for specified link.
0
 

Author Comment

by:arterberry
ID: 12411966
Hello ginsonic,
I am using Windows XP (Service Pack 2) and IE 6.
0
 

Author Comment

by:arterberry
ID: 12412101
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
 
LVL 9

Expert Comment

by:ginsonic
ID: 12418566
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
 
LVL 9

Expert Comment

by:ginsonic
ID: 12490455
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
 
LVL 9

Expert Comment

by:ginsonic
ID: 13180117
no comments?
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question