search

Home  >  Q&A  >  body text

javascript - How to pass value to js in c#

c# Pass a domainurl address to the front end. The code written by c# to the front end is as shown in Figure 1.
This is a self-tuning function. If my front end wants to get this domainurl, how can I directly console.log(cefRuntimeInfo. domainurl), the address can be obtained directly, but if the function setRuntimeInfo is called, the error domain.url is not defined will be reported;
c# is written as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

<code>//c#输出前端配置文件

        public static string domainurl = "http://test.edu.com.cn:8080";

//网页加载完成时触发事件

            LoadHandler.OnLoadEnd += (sender, args) =>

            {

                //判断下触发的事件是不是主框架的

                if (args.Frame.IsMain)

                {

                    //ShowDevTools();W

                    //执行JS,将当前的CEF运行版本等信息通过JS加载到网页上

                    var js = $"$client.setRuntimeInfo({{ domainurl:'{domainurl.ToString()}'}});";

                    ExecuteJavascript(js);

                }

 

 

            };

 

        }</code>

[I am a front-end, please give me some advice on how to get the domainurl as my ajax interface address]

曾经蜡笔没有小新曾经蜡笔没有小新2795 days ago673

reply all(1)I'll reply

  • phpcn_u1582

    phpcn_u15822017-05-16 13:26:17

    Save it in a global variable

    For example:
    willconsole.log(cefRuntimeInfo.domainurl);

    changed to

    1

    2

    <code>window.domaiurl = cefRuntimeInfo.domainurl;

    </code>

    A better suggestion is to ask your colleagues to see how they do it. I feel this is related to the internal framework of your company.

    reply
    0
  • Cancelreply