[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Decorating a innerHTML or innerText

Posted on 2006-03-30
11
Medium Priority
?
1,413 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:DHamilton01
  • 6
  • 5
11 Comments
 
LVL 36

Expert Comment

by:Zyloch
ID: 16336755
I am not sure what put_innerText or put_innerHTML is (some type of function?)

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.
0
 

Author Comment

by:DHamilton01
ID: 16336900
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
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 16337176
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DHamilton01
ID: 16337262
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
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 16337273
Depends on what the onclick is. You can try putting <span onclick="etc."></span> around it.
0
 

Author Comment

by:DHamilton01
ID: 16337310
I mean, when the user mouse clicks the phone number (I want an event to fire...).

(Maybe I am not understanding your question...

0
 

Author Comment

by:DHamilton01
ID: 16337385
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
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 16337767
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.
0
 

Author Comment

by:DHamilton01
ID: 16337916
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(‘...’)>...</span>

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)...!)

0
 
LVL 36

Accepted Solution

by:
Zyloch earned 1500 total points
ID: 16338011
I see what you are saying. There is no way to have the go() function in Javascript go back to a C++ method as that could be a security risk. The only way I know to do this would be using go() to use AJAX and callback to server-side code that would execute your C++ program (possibily with shell_exec() in PHP, for example) with parameters that your C++ code will use to determine what method to run.
0
 

Author Comment

by:DHamilton01
ID: 16338241
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::insertAdjacentHTML 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::insertAdjacentHTML method to insert script, you must include the DEFER attribute in the script element.

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question