카테고리 없음

twebbrowser newwin parameters

knoen 2014. 2. 5. 23:20


twebbrowser newwin parameters

Asked by: pistacerSolved by: 

------------------------------------------------
<a href="#" onClick="window.open('Foto_album/pondelok_26_2001/P1290421.jpg','okno','width=620,height=500,toolbar=no,location=no,directories=no,status=no,scrollbars=no,copyhistory=no,noresize')">
     PICTURE</a>
------------------------------------------------

when i have on the page link as here, it will open the new browser window with some modified properties - width, height, ...
can i in onBeforeNavigate determine a values of this parameters?

to this time, i used this restriction in our pages:
------------------------------------------------
<a href="#" onClick="window.open('P1290414.jpg?width=620,height=510,toolbar=no,location=no,directories=no,status=no,scrollbars=no,copyhistory=no,noresize','okno','width=620,height=500,toolbar=no,location=no,directories=no,status=no,scrollbars=no,copyhistory=no,noresize')">
     PICTURE</a></td>
------------------------------------------------
... all parameters are opied to the url, but this is wery "huge" solution, i dislike it.

the best solution would be a direct access.

Jump to Answer

ID: 20131871

Comments

Expert Comment

by: f15iaf on 2001-06-08 at 04:09:42ID: 6167269

Try to use onnewwindow2 event:
var
   win:variant;
begin
     win:=ppdisp;
     you can get all the values 
     win.height;
     win.width
     win.url
     win.name 
and so on
     cancel:=true;
     to open a new window use
     win.open(.......);
.
.
.
.
.
end;

Author Comment

by: pistacer on 2001-06-08 at 04:38:06ID: 6167314

it sounds pretty, but it wont work

checked this:

procedure TForm1.wbNewWindow2(Sender: TObject; var ppDisp: IDispatch;
  var Cancel: WordBool);
var
  wn:variant;
  wh,ww:longint;
begin
  wn:=ppdisp;
  wh:= wn.height;    // here it shooted an error
  ww:= wn.width;
//  wn.url
//  wn.name
  showmessage(inttostr(wh) + ' - ' + inttostr(ww));
end;

Expert Comment

by: f15iaf on 2001-06-08 at 05:00:59ID: 6167381

Here is the correction
Try this:
procedure TForm1.wbNewWindow2(Sender: TObject; var ppDisp: IDispatch;
 var Cancel: WordBool);
var
 wn:variant;
 wh,ww:longint;
begin
 wn:=ppdisp;
 wh:= wn.document.body.clientWidth;
 ww:= wn.document.body.clientHeight;
//  wn.url
//  wn.name
 showmessage(inttostr(wh) + ' - ' + inttostr(ww));
end;

Author Comment

by: pistacer on 2001-06-08 at 06:51:34ID: 6167793

no, no, no ... :-(((

do not works ... but i tried the first style (wn.height) in onbeforenavigate2 and there it do not raises an errror and when pdisp = webbrowser1.application, then the walues are not zero and are correctr. :-))))

wich object is passed thru pdisp? it aint window, nor document. i am asking because i would like to determine the ohers walues (toolbar, location, directories, status, menubar ...) and they can be text or boolean typed and under other names stored.. 

Accepted Solution

by:  on 2001-06-08 at 11:44:28ID: 6168960

This will provide some of the functionality you are looking for. It does not prevent resizing or scrollbars. Scrollbars can be prevented in the pages you are displaying though using: <body scroll="no"> 

This creates a new instance of the IE Browser through automation. This gives you access to the automation properties that it exposes. With the following procedure you can control the NewWindow2 event.

Add MSHTML to your uses clause.
NewWindow2 Procedure:(Captures/Cancels the NewWindow2 URL and strips it down to just the URL without the target then uses OPENIE)

procedure TForm1.DynamicWBNewWindow2(Sender: TObject; var ppDisp: IDispatch;
  var Cancel: WordBool);
var
  Doc: IHTMLDocument2;
  sURL: string;
  Flags: OLEVariant;
begin
  Flags := 0;
  begin
    Cancel := True;
    Doc := IHTMLDocument2(TWebBrowser(Sender).Document);
    sURL := Copy(Doc.activeElement.outerHTML, pos('href=',
      Doc.activeElement.outerHTML) + 5, length(Doc.activeElement.outerHTML) -
      pos('href=', Doc.activeElement.outerHTML) + 5);
    sURL := Copy(sURL, 0, pos('>', sURL) - 1);
    if pos('"', sURL) = 1 then
      sURL := Copy(sURL, 2, Length(sURL) - 1);
    if pos('"', sURL) <> 0 then
      sURL := Copy(sURL, 0, pos('"', sURL));
    if pos('"', sURL) = Length(sURL) then
      sURL := Copy(sURL, 0, Length(sURL) - 1);
    OpenIE(sURL);
Flags);
  end;
end;


Add comobj to the uses clause.
This is where we create the New Browser window.

procedure OpenIE(aURL: string);
var
  IE: Variant;
  WinHanlde: HWnd;
begin
  if (VarIsEmpty(IE)) then //See if we already have our window open if not open and navigate
  begin
    IE := CreateOleObject('InternetExplorer.Application');
    IE.MenuBar := False;
    IE.AddressBar := False;
    IE.StatusBar := False;
    IE.ToolBar := 0;
    IE.Height := 500;
    IE.Width := 620;
    IE.Visible := true;
    IE.Navigate(aURL);
  end
  else
  begin
    WinHanlde := FindWIndow('IEFrame', nil);// Must already have a window try to open
    if (0 <> WinHanlde) then
    begin
      try
        IE.Navigate(aURL);
        SetForegroundWindow(WinHanlde);
      except
        try // Was closed but we did not know it. Unassign and try again.
          IE := Unassigned;
        except
        end;
        OpenIE(aURL);
      end;
    end
    else
      ShowMessage('Can''t open IE !');
  end;
end;

Rick

Expert Comment

by: RickHalle on 2001-06-08 at 11:48:25ID: 6168968

In your page you would use:
<a href="P1290414.jpg" target="_blank">PICTURE</a>

Rick

Author Comment

by: pistacer on 2001-06-10 at 23:05:34ID: 6175947

uff, thar is, i mean, too complicated. i think, that f15iaf  is more near to that solution i need.
in onbeforenavigate i can catch width and height. now i know, that the pdisp is webbrowser object, wich is owning the properties width, height, document amd so. 
now i need to detect, where in object document i have to read the values of the switchws toolbar, directories .... etc. that will be all.

Expert Comment

by: RickHalle on 2001-06-25 at 00:42:24ID: 6223632

Not waiting forever!

Author Comment

by: pistacer on 2001-06-25 at 01:22:49ID: 6223738

i wrote, that your solution is too complicated for more reasons. one of them is that it requires to use the original IE. my browser is using the TWebBrowser on the application window and i wont put there the original IE windows too.

if you could give me adwice, where i could find required values in the pdisp parameter of onBeforeNavigate method (pdisp is IExplorer object), i would be glad to send the points to you.

Author Comment

by: pistacer on 2001-06-25 at 02:29:45ID: 6223938

i wrote, that your solution is too complicated for more reasons. one of them is that it requires to use the original IE. my browser is using the TWebBrowser on the application window and i wont put there the original IE windows too.

if you could give me adwice, where i could find required values in the pdisp parameter of onBeforeNavigate method (pdisp is IExplorer object), i would be glad to send the points to you.

Expert Comment

by: RickHalle on 2001-06-25 at 02:30:20ID: 6223941

If you are using the TWebBrowser then you are already using an instance of the original IE. You are just using the Delphi Wrapper Component to do it. If you have a TWebBrowser and click a link that opens a new window(or use window.open) then it will be creating another instance of IE. My solution intercepts the new window event(TWebBrowser.NewWindow2) and then uses automation to create the new instance while giving you access to the automation properties of it(MenuBar, AddressBar, etc.).

Rick

Author Comment

by: pistacer on 2001-06-25 at 02:34:02ID: 6223952

i looked again at this piece of your code

begin
                    IE := CreateOleObject('InternetExplorer.Application');
                    IE.MenuBar := False;
                    IE.AddressBar := False;
                    IE.StatusBar := False;
                    IE.ToolBar := 0;
                    IE.Height := 500;
                    IE.Width := 620;
                    IE.Visible := true;
                    IE.Navigate(aURL);
                  end

and i found, that i can read that values thru

pdisp.menubar, pdisp.statusbar, etc, what means, the points will go to you. 

sorry for waiting and that bullshit, i wrote above and twice! i will send the bonus to you!

sorry and thanks