Have a look in 'example.txt'. I hope it will help you. regards. -- B�atrice Philippe
[EMAIL PROTECTED] "George Zhang" <[EMAIL PROTECTED]> a �crit dans le message de news:[EMAIL PROTECTED] > Hi all, > > I'm modifying the mfcembed application to execute javascript from the > C++ code. > > After searching around the threads in this alias, I got below piece of > code, which compilers, but > won't work. I tried to use JS_EvaluateScript to execute script > "alert(\'This is written from code!')" > and "document.write(\"This is written from code!\")" but both failed. > > Could anybody give me any hints to investigate ? > > Thanks, > > -George Z. > > --- Snip --- > nsresult GetContextFromDocument(nsIDocument *doc, JSContext **cx) > { > nsCOMPtr<nsIScriptGlobalObject> sgo; > doc->GetScriptGlobalObject(getter_AddRefs(sgo)); > if (!sgo) { > // No script global, no context. > return NS_OK; > } > > nsCOMPtr<nsIScriptContext> scx; > sgo->GetContext(getter_AddRefs(scx)); > if (!scx) { > // No context left in the old scope... > return NS_OK; > } > > *cx = (JSContext *) scx->GetNativeContext(); > return NS_OK; > } > > void CBrowserView::OnNavBack() > { > // if (mWebNav) > // mWebNav->GoBack(); > > mWebNav->LoadURI(NS_ConvertASCIItoUCS2("file:///C:/test.html").get(), > nsIWebNavigation::LOAD_FLAGS_NONE, > nsnull, > nsnull, > nsnull); > > nsCOMPtr<nsIDOMDocument> domDoc; > mWebNav->GetDocument(getter_AddRefs(domDoc)); > nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc)); > > // gets the JSContext > JSContext *cx; > GetContextFromDocument(doc, &cx); > > char *script = "alert(\'This is written from code!')"; > //char *script = "document.write(\"This is written from code!\")"; > > jsval rval; > JSString *str; > JSBool ok = JS_EvaluateScript(cx, JS_GetGlobalObject(cx), script, > strlen(script), NULL, NULL, &rval); > } > --- Snip --- > > // I used below sample test.html for the test. > <html> > <head> > <script>var counter = 1; > </script> > </head> > <body> > <div id='theDiv'>test text</div> > </body> > </html> begin 666 example.txt M(" @2E-2=6YT:6UE("IR=" ]($I37TYE=U)U;G1I;64H,3 P,# P,$PI.PT* M(" @:[EMAIL PROTECTED]"!R=" ]/2!.54Q,("D-"B @('L-"B @(" @(&9P<FEN=&8H;49I M;&4L(EQN(&YO(')U;G1I;[EMAIL PROTECTED]&]P+B!<;B(I.PT*(" @(" @9F9L=7-H M*&U&:6QE*3L-"B @(" @(')E='5R;B!F:6YA;%]R97-U;'0[#0H@("!]#0H- M"B @($I30V]N=&5X=" J8W@@/2!*4U].97=#;VYT97AT*')T+" X,3DR*3L- M"B @(&EF("@@8W@@/[EMAIL PROTECTED],3" I#0H@("![#0H@(" @("!F<')I;G1F*&U& M:6QE+")<;B!N;R!C;VYT97AT("T@<W1O<"[EMAIL PROTECTED]&XB*3L-"B @(" @(&9F;'5S M:"AM1FEL92D[#0H@(" @("!R971U<[EMAIL PROTECTED]<F5S=6QT.PT*(" @?0T* M#0H@("!*4T-L87-S(&=L;V)A;$-L87-S(#T-"B @('L-"B @(" @(D=L;V)A M;"(L(# L#0H@(" @($I37U!R;W!E<G1Y4W1U8BP@($I37U!R;W!E<G1Y4W1U M8BP-"B @(" @2E-?4')O<&5R='E3='5B+" @2E-?4')O<&5R='E3='5B+ T* M(" @("!*4U]%;G5M97)A=&53='5B+"!*4U]297-O;'9E4W1U8BP-"B @(" @ M2E-?0V]N=F5R=%-T=6(L(" @2E-?1FEN86QI>F53='5B#0H@("!].PT*#0H@ M("!*4T]B:F5C=" J84=L;V)A;$]B:F5C=" ]($I37TYE=T]B:F5C="AC>"P@ M)F=L;V)A;$-L87-S+" P+" P*3L-"B @($I37TEN:713=&%N9&%R9$-L87-S M97,[EMAIL PROTECTED](&%';&]B86Q/8FIE8W0I.PT*(" -"@T*(" @:G-V86P@<G9A;#L- M"B @('5I;G1.(&QI;F5N;R ](# [#0H-"B @(&-H87(J(&%38W)I<'1?=&UP M(#T@(GMV87(@:2 ]("<N;W)G)[EMAIL PROTECTED](&$@/2 G:'1T<#HO+R<[('9A<B!M M>5=E8B ](&$K)W=W=RYM;WII;&QA)RMI.R!M>5=E8BYT;U-T<[EMAIL PROTECTED] M.PT*(" @8VAA<B!A4V-R:7!T7W1M<#);-# Y-ET[#0H@("!S=')C<'DH85-C M<FEP=%]T;7 R+"!A4V-R:7!T7W1M<"D[#0H-"B @($I37T5V86QU871E4V-R M:7!T*&-X+"!A1VQO8F%L3V)J96-T+"!A4V-R:7!T7W1M<#(L( T*(" @(" @ M(" @(" @(" @(" @(" @<W1R;&5N*&%38W)I<'1?=&UP,BDL(")S8W)I<'0B M+"!L:6YE;F\L("9R=F%L*3L-"B @($I34W1R:6YG("IS='([#0H@("!S='(@ M/2!*4U]686QU951O4W1R:6YG*&-X+"!R=F%L*3L-"@T*(" @8VAA<B J<F5S M=6QT7V-H87(@/2!*4U]'9713=')I;F=">71E<RAS='(I.PT*(" @8VAA<B!R M97-U;'1?8VAA<C);-# Y-ET[#0H@("!S=')C<'DH<F5S=6QT7V-H87(R+"!R M97-U;'1?8VAA<BD[#0H@("!F<')I;G1F*&U&:6QE+")<;G!L87E?<V-R:7!T M7V-A;&PH*2 M('-C<FEP="!R97-U;'[EMAIL PROTECTED](@2E-?0V%L;$9U;F-T:6]N M*"[EMAIL PROTECTED] E<UQN(BP@<F5S=6QT7V-H87(R*3L-"B @(&9F;'5S:"AM1FEL92D[ "#0H` ` end _______________________________________________ mozilla-embedding mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-embedding
