Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding and calling JavaScript programmatically

5 views
Skip to first unread message

sasha

unread,
Dec 5, 2008, 1:01:02 PM12/5/08
to
Hello!

I'd like to make use of Google translation APIs in a dynamically created
web page. Could someone suggest a place that contains information on how
to do that?

Here is the info on Google language translation:
http://code.google.com/apis/ajaxlanguage/documentation/#Examples

Here is what I do in my code:

TComInterface <IHTMLDocument2> doc( disp );

TComInterface <IHTMLElement> element;

createElement( disp, "script", element );

TComInterface <IHTMLScriptElement> scriptE( element );

// is this the correct way of adding script's text?

if ( scriptE ) {
scriptE->put_text( CComBSTR( "<script type=\"text/javascript\"
src=\"http://www.google.com/jsapi\"></script> \
<script type=\"text/javascript\"> \
google.load(\"language\", \"1\" ); \
</script>" ) );
}

At this point - where do I add the script element? To the body, head?

Where do I add the actual code to perform the translation and how do I
execute it?

google.language.translate("Hello world", "en", "es", function(result) {
if (!result.error) {
var container = document.getElementById("translation");
container.innerHTML = result.translation;
}
});

TIA,
.a

0 new messages