How to post a tweet using Codebird PHP from pop-up window
In the button click, you need another function that open the popup along with a tweet button.
Add the click event listener as postTweet
to the new tweet button.
I created a sample snippet. Check it below.
To show the real time preview, you need to add the keyup
event listener to the textarea which should copy it's value and add it as the innerHTML
of the preview pane.
function openTweet(){ document.getElementsByClassName("preview")[0].style.display=""; document.getElementById("tweetPr").innerHTML = document.getElementById("tweet").value; document.getElementById("tweet").addEventListener("keyup", function(){ document.getElementById("tweetPr").innerHTML = document.getElementById("tweet").value; }); document.getElementsByClassName("download-share")[0].style.display="none";}function postTweet() { $.ajax({ type: "POST", url: 'tweet.php', data:{action:'call_this'}, success:function(html) { alert('Success!'); } });}
<div style="display:none;" class="preview"><textarea id="tweet"> </textarea><div id="tweetPr"></div><button onclick="postTweet();">Tweet</button></div><button class="download-share" onclick="openTweet()">Download and Share</button>
First things first, you(codebird) are using the twitter API to post to twitter, which makes use of the statuses/update endpoint in the API. This call is a server to server call, ie from the server where your files are hosted to the twitter server.https://dev.twitter.com/rest/reference/post/statuses/update
There are 2 possibilities i see for you to accomplish what you have in mind
-first would be to use twitters web intent system with which you can send the tweet as a query string which would bring up the popup provided you have included the twitter js fileshttps://dev.twitter.com/web/tweet-button/web-intent
-second if thats not really your style then you could try something like what @ceejayoz mentioned making a new window created by you recreating the necessary inputs as shown in the picture and follow the same procedure you have now
Now to your question, Since you have an image the web intent option will not work, but if its a link with an image( twitter cards ) then i think the twitter bots should be able to read through the page and show you a preview in the popup provided you have the right meta tags on the linked page
Try use the function window.open
https://www.w3schools.com/jsref/met_win_open.asp
function postTweet() { $.ajax({ type: "POST", url: 'tweet.php', data:{action:'call_this'}, success:function() { success = true } }); if(success) { window.open('tweet.php', "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400") }}