DHamilton01
asked on
Decorating a innerHTML or innerText
I am enumerating the elements in IE documents (C++) and searching them for phone numbers. If I find one I want to decorate it (underline), but just the phone number, which may be embeded within tags, text or other element composition.
Can any one tell me how to, essentually, take the element string apart and just decorate the middle segment (the phone number), and rewrite the whole element string back to the page? (I don't know JS, so if you can suggest syntax, it will help a lot).
I have tried 'put_innerText()' and 'put_innerHTML()' and but both return a HRESULT error value (-2146827688) when I try to 'put' the element text. I cannot tell if this is because the decoration that I am trying to apply is syntactically incorrect, the element is not 'writtable', or some other reason...
Thanks for your help
- Dick
Can any one tell me how to, essentually, take the element string apart and just decorate the middle segment (the phone number), and rewrite the whole element string back to the page? (I don't know JS, so if you can suggest syntax, it will help a lot).
I have tried 'put_innerText()' and 'put_innerHTML()' and but both return a HRESULT error value (-2146827688) when I try to 'put' the element text. I cannot tell if this is because the decoration that I am trying to apply is syntactically incorrect, the element is not 'writtable', or some other reason...
Thanks for your help
- Dick
ASKER
Zyloch,
The 'put' functions are methods of the IHTMLElement interface.
I'm not sure how you are suggesting that this can be done. It seems that some taging or style sheet must be applied to the phone number so that it will be decorated. I am not sure what that tagging should be, nor how to replace the element containing the phone number back to the document.
I am using a function that I wrote to find numbers that are in a phone number format in the element contents.
- Dick
The 'put' functions are methods of the IHTMLElement interface.
I'm not sure how you are suggesting that this can be done. It seems that some taging or style sheet must be applied to the phone number so that it will be decorated. I am not sure what that tagging should be, nor how to replace the element containing the phone number back to the document.
I am using a function that I wrote to find numbers that are in a phone number format in the element contents.
- Dick
I would think the <u></u> tag would be fine. I am not familiar with IHTMLElement; it is with C++ right? If you cannot get put_innerText() or put_innerHTML() to work right, you might get more feedback in that forum then.
ASKER
Zyloch,
Actually, that helped a lot.
Can you tell me how to simularly add a tag that will cause an 'onClick' event to fire?
Thanks
Actually, that helped a lot.
Can you tell me how to simularly add a tag that will cause an 'onClick' event to fire?
Thanks
Depends on what the onclick is. You can try putting <span onclick="etc."></span> around it.
ASKER
I mean, when the user mouse clicks the phone number (I want an event to fire...).
(Maybe I am not understanding your question...
(Maybe I am not understanding your question...
ASKER
more...
I have associated a event sink with the window (using the C++ IHTMLElement method 'pElem->put_onclick(Sink)' ). This will cause an event to fire into my sink any time the user clicks (anywhere) on the element. I want issolate that click event so that it only will fire when my newly decorated phone number has been touched. I suspect that there is JS (or even HTML) that will fire into my sink. (Maybe it is defined by the other (="etc.") side of the onclick tag you note above).
What is '="etc."'. What does that tell the IE to do when the tag is clicked? Can I enter something after the equal sign that will cause it to fire into my sink?
Thanks
I have associated a event sink with the window (using the C++ IHTMLElement method 'pElem->put_onclick(Sink)'
What is '="etc."'. What does that tell the IE to do when the tag is clicked? Can I enter something after the equal sign that will cause it to fire into my sink?
Thanks
Perhaps you can use put_innerHTML or whatever you use to put a <span> tag around the <u> tags (I would tell you to use CSS itself and put text-decoration:underline; as a style instead of <u> tags but I'm not sure how to do that with IHTMLElement). Put after you put the <span> tags, you can probably use put_onclick. The equal sign if for when you're writing HTML yourself.
ASKER
Zyloch,
I am trying to find out what the 'span' tag is... it seems like it is some kind of blocking tool (ie. a means of embedding some html, with in other tagged html...(?)).
I think my problem is the syntax to bridge between the click event from JS to a C++ function call.
I have found this frament in a book on JS:
<span onmouseover=”hilite(this)” onmouseout=”revert(this)”
onclick=”go(‘...’)>...</sp an>
I wonder if the "go('...')" syntax could be used to go to a C++ method somehow. Usually languages will provide a means of getting to others...
(The book I have on JS, though pound-for-pound should contain everything there is know about JS, is not very easy to search for syntax and options associated with tags (etc)...!)
I am trying to find out what the 'span' tag is... it seems like it is some kind of blocking tool (ie. a means of embedding some html, with in other tagged html...(?)).
I think my problem is the syntax to bridge between the click event from JS to a C++ function call.
I have found this frament in a book on JS:
<span onmouseover=”hilite(this)”
onclick=”go(‘...’)>...</sp
I wonder if the "go('...')" syntax could be used to go to a C++ method somehow. Usually languages will provide a means of getting to others...
(The book I have on JS, though pound-for-pound should contain everything there is know about JS, is not very easy to search for syntax and options associated with tags (etc)...!)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Zyloch,
Thanks for all the info. It has helped to get focused on the issues.
FYI... here is some documentation on a C++ interface method that might hold some promise, as part of the solution:
Thanks - Dick
IHTMLElement::insertAdjace ntHTML Method
-------------------------- ---------- ---------- ---------- ---------- ---------- ----
Inserts the given HTML text into the element at the location.
Syntax
HRESULT insertAdjacentHTML( BSTR where,
BSTR html
);
Parameters
where
[in] BSTR that specifies where to insert the HTML text, using one of the following values:
beforeBegin
Inserts html immediately before the object.
afterBegin
Inserts html after the start of the object but before all other content in the object.
beforeEnd
Inserts html immediately before the end of the object but after all other content in the object.
afterEnd
Inserts html immediately after the end of the object.
html
[in] BSTR that specifies the HTML text to insert. The string can be a combination of text and HTML tags. This must be well-formed, valid HTML or this method will fail.
Return Value
Returns S_OK if successful, or an error value otherwise.
Remarks
If the text contains HTML tags, the method parses and formats the text as it is inserted.
You cannot insert text while the document is loading. Wait for the onload event to fire before attempting to call this method.
When using the IHTMLElement::insertAdjace ntHTML method to insert script, you must include the DEFER attribute in the script element.
Thanks for all the info. It has helped to get focused on the issues.
FYI... here is some documentation on a C++ interface method that might hold some promise, as part of the solution:
Thanks - Dick
IHTMLElement::insertAdjace
--------------------------
Inserts the given HTML text into the element at the location.
Syntax
HRESULT insertAdjacentHTML( BSTR where,
BSTR html
);
Parameters
where
[in] BSTR that specifies where to insert the HTML text, using one of the following values:
beforeBegin
Inserts html immediately before the object.
afterBegin
Inserts html after the start of the object but before all other content in the object.
beforeEnd
Inserts html immediately before the end of the object but after all other content in the object.
afterEnd
Inserts html immediately after the end of the object.
html
[in] BSTR that specifies the HTML text to insert. The string can be a combination of text and HTML tags. This must be well-formed, valid HTML or this method will fail.
Return Value
Returns S_OK if successful, or an error value otherwise.
Remarks
If the text contains HTML tags, the method parses and formats the text as it is inserted.
You cannot insert text while the document is loading. Wait for the onload event to fire before attempting to call this method.
When using the IHTMLElement::insertAdjace
You should be able to just use C++ for this; a simple way (that doesn't always work in case the # is stuck in Javascript for instance), would just be to use a regular expression replacement. I'm not too sure how you're searching for your phone number; if you are using regex (not sure how it works in C++), it shouldn't be too difficult to adapt it.