I found it myself

here is the html code

<html><head></head><body>

<script language="javascript">

function bob(param1)
{
   document.location.href=param1;
   //return 123;
}

</script>

<a href="javascript:bob();">BOB href</a>
<br/>
<a href="#" onclick="bob()">BOB onclick</a>

</body></html>

and the C++ code

nsCOMPtr<nsIScriptGlobalObjectOwner>
theGlobalObjectOwner(do_GetInterface(mWebBrowser));

if (theGlobalObjectOwner) {
        JSFunction* jsf;
                  nsIScriptGlobalObject *theGlobalObject ;
        theGlobalObjectOwner->GetScriptGlobalObject(&theGlobalObject);
        nsIScriptContext *theScriptContext =theGlobalObject->GetContext();

        nsIPrincipal *thePrincipal = nsnull;
        PRBool IsUndefined;
        nsString theReturnValue;
        nsresult rv =
theScriptContext->EvaluateString(NS_LITERAL_STRING("bob('http://www.yahoo.fr');"),
nsnull,thePrincipal, "", 1, nsnull, (nsAString &)theReturnValue,
&IsUndefined);


philippe who is so alone
philippe wrote:
> Hello
>
> I loaded a page from an embedded page.
>
> I want to execute a script
>
> here is my code
>
>               nsCOMPtr<nsIScriptGlobalObjectOwner>
> theGlobalObjectOwner(do_GetInterface(mWebBrowser));
>               if (theGlobalObjectOwner) {
>               JSFunction* jsf;
>                   nsIScriptGlobalObject *theGlobalObject ;
>                               
> theGlobalObjectOwner->GetScriptGlobalObject(&theGlobalObject);
>                               nsIScriptContext *theScriptContext 
> =theGlobalObject->GetContext();
>
>                               JSObject *theGlobalJSObject = 
> theGlobalObject->GetGlobalJSObject();
>                               JSContext *theJSContext =
> (JSContext*)theScriptContext->GetNativeContext();
>
>                               const char* script_PA="alert(10);";
>
>                               jsval reval=0;
>                               uintN lineno=0;
>                               JSBool
> ok=JS_EvaluateScript(theJSContext,theGlobalJSObject,script_PA,strlen(script_PA),"script",lineno,&reval);
>
> }
>
> ok is always false and nothing appends.
>
> Do you have , already executed a script into an existing context?
> 
> AM I wrong
> 
> Thank's for help
> 
> philippe

_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to