javascript - 如何在脚本标签的 index.html 中使用 Bowser Javascript 库?
问题描述
我需要在我的 AngularJS 应用程序中使用 Javascript 库,但在初始化 Angular 应用程序之前,我需要在 index.html 中使用它。
这是图书馆:https ://github.com/lancedikson/bowser
它通常是这样使用的:
const browser = Bowser.getParser(window.navigator.userAgent);
console.log(`The current browser name is "${browser.getBrowserName()}"`);
// The current browser name is "Internet Explorer"
问题是,在我在脚本标签中定义库之后:
<script src="lib/bower/..../bowser.js"></script>
我可以像这样在 index.html 中的下一个脚本标签中立即使用它吗?
<script>
const browser = Bowser.getParser(window.navigator.userAgent);
...
</script>
目前,Bowser 是未定义的。
解决方案
检查Bowser
代码后,它看起来没有大写。此外,您提供的 bowser 库文件可能不打算以这种方式使用。一种解决方案是从 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>
推荐阅读
- testing - 如何在 TestNG 中将跳过的测试用例标记为失败?
- c# - 如何在 C# 中验证 Podio
- jquery - 从ajax jquery函数无法在codeigniter中获取多个数据的数组
- github - 如何为相应的提交启用和使用“提交更改”部分中自动填充的灰色提交消息?
- android - 在 FirestoreRecyclerAdapter 中膨胀多个布局
- multithreading - 纹理名称在OpenGL中是唯一的吗?
- java - Java变量初始化不同的处理方式?
- c++ - 无法从文件中查找和打印具有特定前缀的数据
- laravel - 如何将 vuex 计算属性传递给 vuejs 图表数据?
- docker - Docker坚持课程教程