![]() |
javaScript add to webbrowser
Hallo ich hab da ein problem mit zugriffsverletzungen in dem Code
Procedur zum hinzufügen von Javascript in den Browser
Delphi-Quellcode:
ondocomentcomplete Ereigniss
procedure AppendToWB(document: IHTMLDocument2);
var novoScript : IHTMLDOMNode; i: integer; ole_index: OleVariant; frame_dispatch: IDispatch; frame_win: IHTMLWindow2; frame_doc: IHTMLDocument2; begin if Assigned(document) then begin novoScript := document.createElement('script') as IHTMLDOMNode; (novoScript as IHTMLScriptElement).text := 'function setTimeout(){};function window.focus(){};function focus(){};function window.alert(){};function alert(){}; function window.confirm(){};function confirm(){}; function window.prompt(){};function prompt(){};function window.open(){};'; (document.body as IHTMLDOMNode).appendChild(novoScript); for i:=0 to (document.Frames.Length -1) do begin ole_index := i; frame_dispatch := document.Frames.Item(ole_index); if frame_dispatch <> nil then begin frame_win := frame_dispatch as IHTMLWindow2; frame_doc := frame_win.document; if Assigned(frame_doc) then begin novoScript := frame_doc.createElement('script') as IHTMLDOMNode; (novoScript as IHTMLScriptElement).text := 'function setTimeout(){};function window.focus(){};function focus(){};function window.alert(){};function alert(){}; function window.confirm(){};function confirm(){}; function window.prompt(){};function prompt(){};function window.open(){};'; (frame_doc.body as IHTMLDOMNode).appendChild(novoScript); end; end; end; end; end;
Delphi-Quellcode:
Also das ondocomentcomplete Ereigniss wird ja jedesmal aufgerufen wenn Seite/Frame geladen wurde und mit dem Verleich stellt man ja fest ob alle Frames der Seite geladen wurden. Wenn das geschieht soll er die procedur AppendToWB(document) aufrufen , was er auch tut. In der Prozedur soll er dann zu der Seite mit allen Frames die Javascriptelemente hinzufügen. Für die Hauptseite ist das niemals das problem , nur bei dem Frames erhalte ich bei frame_doc := frame_win.document; die Zugriffsverletzung . Ich weis nicht was ich falsche mache , hat jemand einen Tip ?
procedure TForm1.WBLoad(ASender: TObject; const pDisp: IDispatch;var URL: OleVariant);
var currentBrowser: IWebBrowser2; topBrowser: IWebBrowser2; document: IHTMLDocument2; windowName: string; begin currentBrowser := pDisp as IWebBrowser2; topBrowser := (ASender as TWebBrowser).DefaultInterface; if currentBrowser = topBrowser then begin document := currentBrowser.Document as IHTMLDocument2; AppendToWB(document); end end; |
Re: javaScript add to webbrowser
ok habs jetzt doch selber herausgefunden
Delphi-Quellcode:
manchmal ich weniger halt doch mehr :)
procedure AppendToWBA(document: IHTMLDocument2);
var novoScript : IHTMLDOMNode; begin if Assigned(document) then begin novoScript := document.createElement('script') as IHTMLDOMNode; (novoScript as IHTMLScriptElement).text := 'function setTimeout(){};function window.focus(){};function focus(){};function window.alert(){};function alert(){}; function window.confirm(){};function confirm(){}; function window.prompt(){};function prompt(){};function window.open(){};'; (document.body as IHTMLDOMNode).appendChild(novoScript); end; end; procedure TForm1.WBLoad(ASender: TObject; const pDisp: IDispatch;var URL: OleVariant); var currentBrowser: IWebBrowser2; document: IHTMLDocument2; begin currentBrowser := pDisp as IWebBrowser2; document := currentBrowser.Document as IHTMLDocument2; AppendToWBA(document); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:40 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz