I have a need to display our application widget within a third-party website (think things like GetSatisfact开发者_JAVA技巧ion, UserVoice and other feedback widgets that people use).
What is the safest and most reliable way to do this? I can think of some criteria and issues already:
- The code needs to be framework and language independent. Even though my app is ASP.NET, the 'launcher' will be run in any HTML page that belongs to our customers. So I suppose that limits me to HTML and Javascript only.
- The function needs to be very easy to call. So that implies a
<script scr='mywebsite.com/widget.aspx' ...>
as the sole thing to give to my customer. - There is to be no use of CSS. Or rather, I can style things, but without a CSS file, as that could pull in styles that conflict with what my customer is running.
- There must be no use of libraries such as JQuery. I mention this because I can imagine problems if we pull in a JQuery version that differs from our customer's, thus ruining their site with our code.
Ideally, is there a well established piece of code I can use to get started?
Probably the easiest way to isolate your widget from all of the customer's JS and CSS code is to embed it in an IFRAME.
If necessary, you can provide a script that will inject the IFRAME into the document. You can keep your variables isolated from the global namespace by encasing everything like so:
(function() {
//inject iframe into document.
})();
精彩评论