//How can I trigger auto click without clicking, so that it auto show the share dialog
<div>
<button type="button" id="share-button">Share</button>
</div>
//How can I trigger auto click without clicking, so that it auto show the share dialog
<div>
<button type="button" id="share-button">Share</button>
</div>
document.getElementById("share-button").click()
Insert standard disclaimers about not p***ing people off by clicking on things they dont want to click, etc.
I have tried this method but still cannot auto-click.
<div id="buttons">
<h2>Buttons</h2>
<div>
<button type="button" id="share-button" onclick="share()">Share</button>
</div>
</div>
<script>
window.fbAsyncInit = function () {
FB.init({
appId: 'ID',
autoLogAppEvents: true,
xfbml: true,
version: 'v11.0'
});
};
document.getElementById('share-button').addEventListener('click', share);
function share() {
FB.ui({
display: 'popup',
method: 'share',
href: 'https://developers.facebook.com/docs/',
}, function (response) {
//Debug response (optional)
console.log(response);
});
}
window.onload = function () {
share();
}
//Load the JavaScript SDK asynchronously
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementsById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js"></script>
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.