[英]How to use a Bowser Javascript Library in index.html in script tags?
I need to use a Javascript Library in my AngularJS app, but i need this already in index.html before the angular app is initialized. 我需要在AngularJS应用中使用Javascript库,但是在初始化angular应用之前,我已经在index.html中需要它。
This is the library: https://github.com/lancedikson/bowser 这是库: https : //github.com/lancedikson/bowser
And it is normally used like this: 它通常是这样使用的:
const browser = Bowser.getParser(window.navigator.userAgent);
console.log(`The current browser name is "${browser.getBrowserName()}"`);
// The current browser name is "Internet Explorer"
The problem is, after i define the library in script tags: 问题是,在脚本标记中定义了库之后:
<script src="lib/bower/..../bowser.js"></script>
Can i immediately use this in the next script tag within the index.html like this? 我可以像这样在index.html中的下一个脚本标记中立即使用它吗?
<script>
const browser = Bowser.getParser(window.navigator.userAgent);
...
</script>
At the moment, Bowser is undefined. 目前,Bowser尚未定义。
After checking the Bowser
code it looks like it is not capitalised. 检查
Bowser
代码后,它似乎没有大写。 Further the bowser library file you are serving may not be intended to be used that way. 此外,您正在提供的Bowser库文件可能不打算以这种方式使用。 One solution is to serve a built version of bowser from a CDN:
一种解决方案是从CDN提供Bowser的内置版本:
<script src="https://cdn.jsdelivr.net/npm/bowser@2.5.3/es5.min.js"></script>
<script>
const browser = bowser.getParser(window.navigator.userAgent);
//...
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.