Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function InsertJavascript(const HTMLDocument2: IHTMLDocument2): Boolean;
- // In Delphi variables are declared at the top of a function in a "var" section
- var
- HeadDOM: IHTMLDOMNode;
- HTMLScriptElement: IHTMLScriptElement;
- HTMLScriptDOM: IHTMLDOMNode;
- begin
- // <snip> Get a IHTMLDOMNode representing the HEAD section of the document
- // which is assigned to "HeadDOM" </snip>
- // e.g., insert JQuery script text into document
- HTMLScriptElement := HTMLDocument2.createElement('SCRIPT') as IHTMLScriptElement;
- HTMLScriptElement.setAttribute('id', 'text/javascript', 1);
- // GetDOMNodeFromHTMLElement calls QueryInterface on HTMLScriptElement, passing IHTMLDOMNode
- HTMLScriptDOM := GetDOMNodeFromHTMLElement(HTMLScriptElement);
- // GetResourceAsString calls Win32 API function "FindResource" and returns a string
- // that is the text of the jquery.js file (which is compiled into the BHO DLL)
- HTMLScriptElement.text := GetResourceAsString(PChar(scJQueryJS), PChar('TEXT'));
- // Add the newly created IHTMLDOMNode to the HEAD section of the document
- HeadDOM.appendChild(HTMLScriptDOM);
- end;
Advertisement
Add Comment
Please, Sign In to add comment