简体   繁体   中英

How do I create a “widget” for people? It's just a simple text box with my logo

I want something that the webmaster can copy into his site.

It just needs to have my logo, a text box, and a submit button. (When the user clicks submit using that widget, it forwards to my site.)

I know there are many ways to do this. What is the fastest and easiest?

I don't know about fastest and easiest, but maybe you could write a little JavaScript file that creates and injects the content into a div with a special ID.

This is along the lines of what StackOverflow does for their " flair ."

Fastest way is to just put some HTML code that people can paste in their page. There's no need for buttons or form, just a simple link.

Something on the lines of:

<a href="http://www.yoursite.com/">
<img src="http://www.yoursite.com/yourlogo.jpg" alt="yoursite.com logo" title="Visit yoursite.com!" />
</a>

You'll probably want to add a couple of style tags (eg to avoid borders around the image etc) Also, it would be easy on your site to have a little JS that changes the code above so that people can personalize it (point to different images, different sizes etc etc)

Some may frown upon it but possibly the fastest and easiest way is to use an iframe. It means that the embed code can be quite short + you can change the behaviour at a later date.

Iframe's main advantage is that you don't have to deal with the css that's already included in the page. Might not seem like a big deal but sooner or later you'll run into a page that does something with a css attribute that you just hadn't expected.

It's not pretty but it's worth considering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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