Making use of localized variables in javascript.
2013-05-31 09:53
309 查看
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).
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).
<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).
相关文章推荐
- 【web】Ad in security code, making good use of resource
- Making Use of JavaScript
- [Javascript] Proper use of console.assert in JavaScript
- JavaScript quirk 7: inadvertent sharing of variables via closures
- Making Use of Boost Geometry in MySQL GIS
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- The version of SQL Server in use does not support datatype 'datetime2'.
- The Use of Aliases in ElasticSearch
- [转]How do I use variables in Oracle SQL Developer?
- Use MFC in a Static Library,This may be due to a corruption of the heap....
- Unit Testing in Xcode 4 – use OCUnit and SenTest instead of GHUnit
- Displaying Interval of Time in JavaScript
- the thinking use of DOM in my project
- How to use the pointer of function in a class?
- Sorry: TabError: inconsistent use of tabs and spaces in indentation (alien_invasion.py, line 19)
- iOS 后台定位审核被拒How to clarify the purpose of its use in the location modal?
- Make Cool Use of Windows Remote Desktop In XP
- **PHP错误Cannot use object of type stdClass as array in错误的
- csharp: Use of Is and As operators in csharp
- javascript中的for...in & for...of的使用