Frankline
Frankline

Reputation: 41025

How to create a custom widget using django for use on external sites

I hava a new site that I am working on. The site will have prior agreement with eCommerce sites to include add-ons on their website.

Consider the following example: My website, ABC.com is targeting ecommerce sites. For every ecommerce site that sells product X, I want them to include an add-on that gives buyers the option to purchase service Z if they so desire. ABC.com will be communicating with the ecommerce sites through a REST API.

My challenge is how to integrate my service as an add-on into the external ecommerce sites. This I assume will be in the form of a widget, HTML code, or a bit of javascript. Something similar to the attached image from Amazon.com. I'm aiming to make a simple integration with the external sites to avoid having them do too much on their end.

Is there a best practice on how to handle this?

See an example from Amazon: enter image description here

Upvotes: 0

Views: 289

Answers (1)

Soviut
Soviut

Reputation: 91722

There are a number of ways but the two most common are:

iframe

You create a small page containing only the controls and logic you need which will be embedded in the site using an iframe. The parent site would communicate relevant details, such as product name and product SKU, with the child iframe via URL parameters in the iframe's src attribute. In this case, you wouldn't know if the user actually submitted the parent form.

Javascript widget

You create a small self-contained javascript widget that can be loaded from a CDN. The widget would then target a specific element, or elements, on the page and add your additional form fields. It could then listen for form submit events (or other types of events) and could be responsible for doing AJAX calls directly to your API.

Examples of this are widgets like Stripe which generate buy buttons on a page.

Upvotes: 1

Related Questions