简体   繁体   English

如何在小部件中添加外部javascript库和样式表?

[英]How to add external javascript library and stylesheets in a widget?

I am trying to create a Javascript widget where in the user of the widget will have to add a couple of lines of Javascript to his page which in turn will add an externally hosted javascript to his page. 我正在尝试创建一个Javascript小部件,其中小部件的用户必须在其页面中添加几行Javascript,这又将在其页面中添加外部托管的javascript。 Through this javascript, I'll add HTML code to his page. 通过此javascript,我将HTML代码添加到他的页面。 In this HTML, I'm using Angular Material Library. 在此HTML中,我正在使用Angular Material Library。

I have a few questions: 我有几个问题:

  1. How should I go about this? 我应该怎么做? Can someone share a link of a related tutorial? 有人可以共享相关教程的链接吗?
  2. Is it possible to add external stylesheet and script to the widget? 是否可以将外部样式表和脚本添加到小部件?
  3. How do I avoid any conflicts with the user's own website global objects? 如何避免与用户自己的网站全局对象发生冲突?

You are most likely to create an iframe solution which your Javascript will inject on the page upon rendering. 您最有可能创建一个iframe解决方案,您的Javascript将在呈现时注入到页面上。

Name conflicts can be avoided using naming convention for stylesheets, IIFE for scoping. 使用样式表的命名约定,使用范围的IIFE可以避免名称冲突。

I think your question seems already answered here: Creating a javascript widget for other sites 我认为您的问题似乎已经在这里得到了解答: 为其他网站创建javascript小部件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM