Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 11 to 15 of 15 total |
getElementById with HTML string? |
Fri, Oct 2 2015 10:32 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | PA,
<< This works well. However, to follow your advice to not unnecessarily using external JavaScript, I tried to implement the functionality of the above Javascript in EWB: >> The selectors haven't been added to the WebDOM unit's TDocument external interface. I'll have to add them. For now, as you found already, just use the GetElementByID. Tim Young Elevate Software www.elevatesoft.com |
Fri, Oct 2 2015 10:44 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | PA,
<< Here the compiler did not complain. However, Opere gave me this error message: >> In the WebDOM unit, add this method: external TDOMImplementation emit DOMImplementation = class public { Methods } function createDocument(const namespaceURI: String; const qualifiedName: String; doctype: TDocumentType): TDocument; function createDocumentType(const qualifiedName: String; const publicId: String; const systemId: String): TDocumentType; function createHTMLDocument(const title: String): THTMLDocument; <<<<<<<<<<<<<<< Here function hasFeature(const feature: String; const version: String): Boolean; end; I've added it for 2.02. It was an IE9+ feature that didn't get added in for EWB 2.x. And then your function should look like this: function ExtractElementByIdFromString2(const HTMLString: String; const IdString: String): String; var TempDocument: THTMLDocument; TempElement, TempElement2: TDOMElement; begin TempDocument := window.document.implementation.createHTMLDocument('Test'); // Create a temporary document TempElement := TempDocument.createElement('div'); // Create a temporary element THTMLElement(TempElement).innerHTML := HTMLString; // Set the passed string as HTML to the temporary element TempElement2 := TempDocument.getElementById(IdString); // Find an element with the passed id if Assigned(TempElement2) then Result := THTMLElement(TempElement2).outerHTML else raise Exception.Create('Element not found with ID of "'+IdString+'"'); end; Tim Young Elevate Software www.elevatesoft.com |
Fri, Oct 2 2015 12:49 PM | Permanent Link |
PA | Tim, thank you for the code.
However: The getElementById line does not work. HTMLString is: <!DOCTYPE html> <html> <head> <title>ExtractDiv test</title> <style type="text/css"> ul.c1 {list-style-type: upper-roman} </style> </head> <body> <p>Apples and oranges</p> <div id="main"> <ul class="c1"> <li>Äpfel</li> <li>Birnen</li> </ul> </div> <p>Men and women</p> </body> </html> So you can see that the DOM element with the "main" ID DOES exist. |
Fri, Oct 2 2015 1:34 PM | Permanent Link |
PA | PA wrote:
> However: The getElementById line does not work. Maybe because the getElementById method is not yet implemented in the THTMLDocument class? |
Fri, Oct 2 2015 4:22 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | PA,
<< However: The getElementById line does not work. >> You (and I) didn't add the main div element to the document first. Here's the correct version: function ExtractElementByIdFromString2(const HTMLString: String; const IdString: String): String; var TempDocument: THTMLDocument; TempBodyElement: THTMLElement; TempElement, TempElement2: THTMLElement; begin Result:=''; TempDocument := window.document.implementation.createHTMLDocument('Test'); // Create a temporary document TempElement := THTMLElement(TempDocument.createElement('div')); // Create a temporary element TempBodyElement:=THTMLElement(TempDocument.getElementsByTagName('body')[0]); if Assigned(TempBodyElement) then begin TempBodyElement.appendChild(TempElement); // Add the temporary element to the document TempElement.innerHTML := HTMLString; // Set the passed string as HTML to the temporary element TempElement2 := THTMLElement(TempDocument.getElementById(IdString)); // Find an element with the passed id if Assigned(TempElement2) then Result := TempElement2.outerHTML else raise Exception.Create('Element not found with ID of "'+IdString+'"'); end else raise Exception.Create('No body element found'); end; Tim Young Elevate Software www.elevatesoft.com |
« Previous Page | Page 2 of 2 | |
Jump to Page: 1 2 |
This web page was last updated on Friday, December 6, 2024 at 05:39 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |