/    Sign up×
Community /Pin to ProfileBookmark

Auto Trigger Click button after page loading

I want to trigger auto click share-button after page loading. But it still require manual click using below coding.

<html>
<head>
<meta charset=”utf-8″ />

</head>
<body>

<h1> SDK Demo</h1>

<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>

</body>
</html>

to post a comment

0Be the first to comment 😎

×

Success!

Help @PagiJingga spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...