Board index » delphi » Preventing JavaScript resize in TWebBrowser

Preventing JavaScript resize in TWebBrowser


2004-03-03 03:52:22 AM
delphi146
I have a Delphi app which hosts TWebBrowser, and pages which use JavaScript
to resize the browser window cause the browser to be resized within my app.
I've tried to work around this by trapping OnDocumentComplete and various
other events and then forcing the browser to resize to fit its container,
but this doesn't always work.
Does anyone know a reliable way to prevent JavaScript from resizing
TWebBrowser?
Thanks,
--
Nick Bradbury
www.bradsoft.com
 
 

Re:Preventing JavaScript resize in TWebBrowser

Quote
Does anyone know a reliable way to prevent JavaScript from resizing
TWebBrowser?

I haven't tried this, but TWebBrowser.ControlInterface.Resizable looks worth
a go.
HTH, Simon
 

Re:Preventing JavaScript resize in TWebBrowser

Quote
"Simon" writes:
>Does anyone know a reliable way to prevent JavaScript from
>resizing TWebBrowser?

I haven't tried this, but TWebBrowser.ControlInterface.Resizable
looks worth
Thanks for the reply, Simon. Unfortunately, changing 'Resizable' seems to
have no effect.
--
Nick Bradbury
TopStyle/FeedDemon Support
 

Re:Preventing JavaScript resize in TWebBrowser

In article <4044e5f5$XXXX@XXXXX.COM>, "Nick Bradbury
\(TopStyle/FeedDemon\)" <XXXX@XXXXX.COM>says...
Quote
I have a Delphi app which hosts TWebBrowser, and pages which use JavaScript
to resize the browser window cause the browser to be resized within my app.
I've tried to work around this by trapping OnDocumentComplete and various
other events and then forcing the browser to resize to fit its container,
but this doesn't always work.

Does anyone know a reliable way to prevent JavaScript from resizing
TWebBrowser?

Thanks,

Hey, Nick, did you know that you can modify the JS code in the page as
long as it is not in an external JS file?
I have an example posted around somewhere, either on EE or Delphi Pages.
Let me find it.
Basically, I added an error handler to stop js errors.
 

Re:Preventing JavaScript resize in TWebBrowser

In article <XXXX@XXXXX.COM>,
eshipman@yahoo!!!.com says...
Quote
In article <4044e5f5$XXXX@XXXXX.COM>, "Nick Bradbury
\(TopStyle/FeedDemon\)" <XXXX@XXXXX.COM>says...
>I have a Delphi app which hosts TWebBrowser, and pages which use JavaScript
>to resize the browser window cause the browser to be resized within my app.
>I've tried to work around this by trapping OnDocumentComplete and various
>other events and then forcing the browser to resize to fit its container,
>but this doesn't always work.
>
>Does anyone know a reliable way to prevent JavaScript from resizing
>TWebBrowser?
>
>Thanks,
>
Hey, Nick, did you know that you can modify the JS code in the page as
long as it is not in an external JS file?

I have an example posted around somewhere, either on EE or Delphi Pages.
Let me find it.

Basically, I added an error handler to stop js errors.

Here it is:
************************************************************************
Memo1.Lines.Text =
function stopError() {
return true;
}
window.onerror = stopError;
************************************************************************
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
ovScript: OleVariant;
begin
// Only loading the first script, The error handler only
// needs to be added to the first one.
ovScript :=
WebBrowser1.OleObject.Document.all.tags('SCRIPT').item(0);
Memo1.Lines.Add(ovScript.text);
ovScript.Text := Memo1.Lines.Text;
end;
Looks to me like you should be able to parse the js in ovScript to
see if it contains the resize code and get rid of it. I would suggest
adding the error hadnler as well.
 

Re:Preventing JavaScript resize in TWebBrowser

Now why didn't I think of that ?! Thanks for sharing this - it might save
me a lot of headaches with JS errors :)
--
Nick Bradbury
TopStyle/FeedDemon
"eshipman" <eshipman@yahoo!!!.com>writes
Quote
Here it is:

************************************************************************

Memo1.Lines.Text =

function stopError() {
return true;
}

window.onerror = stopError;


************************************************************************

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
ovScript: OleVariant;
begin
// Only loading the first script, The error handler only
// needs to be added to the first one.
ovScript :=
WebBrowser1.OleObject.Document.all.tags('SCRIPT').item(0);
Memo1.Lines.Add(ovScript.text);
ovScript.Text := Memo1.Lines.Text;
end;

Looks to me like you should be able to parse the js in ovScript to
see if it contains the resize code and get rid of it. I would suggest
adding the error hadnler as well.