twttr.widgets.createShareButton function. Pass a share URL, target parent element, and any custom options.
The code snippets on this page assume widgets.js has successfully loaded on your page. Include an asynchronous script loader on your page while initializing window.twttr as described in our JavaScript loader documentation. All JavaScript code depending on widgets.js should execute on or after twttr.ready.
Arguments
| Parameter | Description | Example value |
|---|---|---|
url | A share URL, or an empty string if you would not like to include a Post composer URL component | https://dev.x.com/ |
targetEl | DOM node of the desired parent element | document.getElementById('container') |
options | Override default widget options. See Post button parameter reference for details | { text: 'Hello world' } |
Example
An element with a DOM ID ofcontainer exists on the page.
container.
Promises
Thetwttr.widgets.createShareButton function returns a Promise. You can execute code after a widget has been inserted onto your page by passing a callback to the resulting promise’s then function.