Making use of localized variables in javascript.

Here is a simple way of using values stored in global resource files to be used in your markup and javascript code. Simply add the following to your markup (aspx page, user control or whatever).

<script type="text/javascript">
    var myVariable = '<%= GetGlobalResourceObject("MyResourceFileName", "MyResourceKey").ToString()%>';
</script>

Once this is done, you can make use of the variable in your javascripts.

Note: These variables cannot be added in separate javascript files, but have to be added to the page directly. However, once added, they can be reached from code in the javascript file if it is imported.

EDIT: The GetGlobalResourceObject method is a standard method in the HttpContext class (link here).

原文地址:https://www.cnblogs.com/frankzye/p/3109803.html