简体   繁体   English

如何在脚本标签的index.html中使用Bowser Javascript库?

[英]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.

相关问题 WebPack 反复将冗余脚本标签注入 index.html 加载 - WebPack repeatedly injects redundant script tags into index.html on load 如何使 Vue 从 assets 文件夹中导入文件,而不是 index.html 内的硬编码脚本标签 - How to make Vue import files from assets folder instead of hardcoded script tags inside of index.html 如何通过自动将NPM“依赖”包含到index.html中<script> tags in VUE JS WEBPACK project? - How to automatically include NPM “dependencies” into index.html through <script> tags in VUE JS WEBPACK project? 如何避免在主机起源index.html上使用脚本标记库CDN链接 - how to avoid script tag library cdn links using on host origin index.html 如何在索引中使用 *ngIf.html angular 8 - How to use *ngIf in index.html angular 8 如何将 index.html/index.jsp 上定义的 Javascript 变量用于 Vue.js? - how to make use of Javascript variable which are defined on index.html/index.jsp to Vue.js? VueJS 3:如何将 JS 脚本注入到 index.html 中,“Type”为“text/javascript” - VueJS 3: How to inject JS script into index.html with "Type" as "text/javascript" Angular 在 index.html 中导入脚本并在组件中使用 - Angular import script in index.html and use it in component 在 index.html 的脚本标签中使用 Vue Composition API - Use Vue Composition API in a script tag in index.html 在对AngularJS应用进行模块化之后,如何将整个项目包含在index.html中,而不必键入很多<script> tags - After modularizing an AngularJS app, how do you include the entire project in the index.html without having to type a ton of <script> tags
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM