What is the simplest way to create a very simple widget that can be used on remote sites?
For example, I have a super simple widget that I want to allow my users to use across sites:
<h1>Headline&开发者_运维知识库lt;/h1>
#mingyeow is the name of the user
<% render "/questions/mingyeow" %>
What would be the easiest way to do?
- exact method to allow this
- javascript vs iframe
- cross site security concerns
I would recommend using an IFrame.
The reasoning behind this is simple:
- If it is definitely just a "simple" widget you're looking to render, then you should be able to design it with a specific set of dimensions in mind.
- IFrame will straight up ensure you have a secure way of rendering the widget off-site, and prevent unscrupulous third parties from modifying this widget in any way (and misrepresent the data you're trying to show, or the branding of your product/service).
- Easiest for third parties to set up.
- You won't step on the toes of the third party, and they won't step on your toes either. Meaning any weird CSS selectors they have, third party JS libraries, etc. None of that will be able to affect your widget.
A Dynamic Image would easily be the best, all web developers, new and experienced (you would hope) should be comfortable with images, images render exactly the same across all browsers, and give you the greatest control over layout. Here's a quick tutorial on how to create a dynamic image using ruby.
Otherwise I'd go for JavaScript which replaces something like <div class="mySiteWidget"></div>
with your code using DOM functions. Although that's just a personal thing I have against frames, I find them clunky.
精彩评论