JS Call of the foreign chapter

Source: Internet
Author: User

C#winform Call JS
ExecutionJs(Javascript) Methodpre-Class knowledge Reserve:1,Jsthe location where the code is placed. method One: Use Microsoft Official components Interop.msscriptcontrol            Scriptcontrolclasssc = new Scriptcontrolclass ();//Declaration VariablesSC. Usesafesubset = true; //allow unsafe code to be executedSC. Language = "JScript"; VBScriptSC. Addcode (Properties.Resources.GetTimes);// properties.resourcesresource File                               the name of the method to execute,parameters to execute/Write the method name if there is no argumentstring str = sc. Run ("Time", newobject[] {"Time ()"}). ToString ();//Special attentionwhenJSwhen there are no parameters in the method,The method name is passed at this time.Disadvantages:              DLL must be carried.              x64 is not supported.difference: Method One requires DLL, method two reflection method is not required DLL.method One does not support X64, method two supports.method Two must be wrapped using the "'" quotation mark when the required argument is a string. Method one does not needMethod two: Using reflection to get the component       /// <summary>        /// GetJStime Stamp -bit// </summary>// <returns></returns>Public stringgettimebyjs ()        {Type obj = Type.gettypefromprogid ("ScriptControl");if (obj = = null) return null;Object ScriptControl = Activator.CreateInstance (obj);obj. InvokeMember ("Language", BindingFlags.SetProperty, NULL, ScriptControl, newobject[] {"JScript"});string js = "Functiontime () {return new Date (). GetTime ()}";obj. InvokeMember ("Addcode", BindingFlags.InvokeMethod, NULL, ScriptControl, newobject[] {js});return obj. InvokeMember ("Eval", Bindingflags.invokemethod,null, ScriptControl, newobject[] {"Time ()"}). ToString ();        }

Have to say the method:           inside the environment variable-system variable-path-point edit, added at the end;. NETFramework (note compiled version) absolute path "Note that there is also a semicolon in front of the system variable can not have Chinese, space: O. direct cmd jec the call to compile. For example: "Jsc/t:library xxx.js"

Video tutorial from: http://www.xuanjics.com/thread-86-1-1.html

Address of the Mystery forum: www.xuanjics.com original King's Landing

QQ Exchange Group: 16885911

JS Call of the foreign chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.