How do I let a user tweet an image? - javascript

We have a twitter button set up where users click on it and a popup opens up to let the user tweet from their own account. How can we include an image with that tweet? (With facebook we've been able to do it).
<div>
<a href="http://twitter.com/share" class="twitter-share-button"
data-url="http://www.mysite.com"
data-text="sharing this with you...."
data-count="none">Tweet</a>
</div>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
<script type="text/javascript">
twttr.events.bind('tweet', function(event) {
window.location = "http://www.mysite.com"
});
</script>

To do this, you'll need to use the API directly (not just their widget). Details on how to post with a media item can be found at the status/update_with_media docs.
If you're looking for a kind of rendering a 'preview' of a link (what Facebook allows through Open Graph), then checkout the Cards documentation.

You can also use the following:
https://dev.twitter.com/rest/media/uploading-media

Related

Masterpass make redirect occur in iframe or prevent navigation

I am attempting to integrate masterpass into an existing .net application. I have followed their documentation but i would like instead of clicking on the masterpass button and being redirected to their sign in page for authentication that their login page open in either a popup or an iframe so that the user is not forced to leave my checkout page. Has anyone had any luck with this? Their page states that express checkout which is essentially what i am looking for is not available in the US or Canada. Has anyone found a work around?
My code looks like this
$(document).ready(function() {
$('#clickMe').click(function () {
masterpass.checkout({
“checkoutId”:”my checkoutId”,
“allowedCardTypes”:[“amex”,”visa”, “etc”],
“amount”:”30.00”
“currency”:”USD”
});
});
});
<script src="https://sandbox.masterpass.com/integration/merchant.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
My Form
<img alt="Checkout with Masterpass" role="button" src="https://static.masterpass.com/dyn/img/btn/global/mp_chk_btn_147x034px.svg" id="clickMe"/>
</div>

show and hide divs on click on another page

List item
I am using the following code to hide a div and show the other.
page1
<a id="show" href="2#dk" onclick='document();'>mylink</a>
<a id="show1" href="2#dh" onclick='document();'>mylink</a>
page 2
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#show").click(function(){
$("dk").show();
$("dh").hide();
});
$("#show1").click(function(){
$("dh").show();
$("dk").hide();
});
});
</script>
</head>
<body>
<div id="dk">mylink</a>
<div id="dh">mylink</a>
</body>
</html>
This works on one page but not after the anchor tag loads up another page.
PREMISE
I have pages:-
first
second
I want links on on page and divs on second page
frist page links
divs
OBJECTIVE
If the page is first page, links need to be on this page
If the page is second page, then I wish to hide the divs that are not link to the link thats clicked
you can see here what i mean even i will put account detials that ppl can look at code and try if they want
http://testscripten.enjin.com/login
username:testscripten
password:test12345
go to admin and then edit
page layout and next to text will a pencil to change html or java
I think you can use window.location.href to get the link of the page you're currently on and then accordingly hide/show your buttons.
JAVASCRIPT
var pageName = window.location.href;
$(document).ready(function(){
if(pageName === "dh"){
$("#show").show();
$("#show1").hide();
} else if(pageName === "dk") {
$("show1").show();
$("show").hide();
}
});
HTML
<a id="show" href="dk">mylink</a> <!--No need for onclick if you're using jQuery-->
<a id="show1" href="dh">mylink</a> <!--No need for onclick if you're using jQuery-->
I am not sure of "dk" and "dh" being real links, if you have kept those as placeholders then this should work.
Simply show/hide based upon the path name containing the strings you specify:
$(document).ready(function(){
$('div.toShowOnFirstPage').toggle(location.pathname.indexOf("first")!== -1);
$('div.toShowOnSecondPage').toggle(location.pathname.indexOf("second")!== -1);
});
use AngularJS and SPA model to avoid page reload.
You can use also variables in url
If you need to reload page and have values on different pages you have to set cookie or webStorage http://www.w3schools.com/html/html5_webstorage.asp
Why don't you use php?

how to pass custom parameter in facebook sharer link

Code 1:
<a id="button" rel="nofollow" href="http://www.facebook.com/share.php?" onclick="return fbs_click()" target="_blank">
<script>
function fbs_click() {
u=location.href;
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),
'sharer',
'toolbar=0,status=0,width=626,height=436');
return false;
}
Here Title "t" is not working but i want to display custom title, summary, url and image so, I tried something like this
Code 2:
<a id="button" href="http://www.facebook.com/sharer.php?
s=100
&p[url]=<?php echo $pressurl;?>
&p[images][0]=http://myurl/images/linkedin_image.png
&p[title]=mytitle
&p[summary]=containsummary ">
In both the cases nothing happened it automatically get some content (title,image,summary) from the above mentioned url and I want to display custom title,image and summary in facebook share page and i dono how to use og meta tag and what s=100 it means?..
Instead of using the sharer.php script on Facebook, you can use the Facebook JavaScript SDK to make a custom share dialog.
<!-- include Facebook JavaScript SDK -->
<!-- share link -->
Share to Facebook
<script type="text/javascript">
function fb_share() {
// facebook share dialog
FB.ui( {
method: 'feed',
name: "Your Page Title",
link: "https://www.webniraj.com/link-to-page/",
picture: "https://stackexchange.com/users/flair/557969.png",
caption: "Some description here"
}, function( response ) {
// do nothing
} );
}
// add click event to link using jQuery
$(document).ready(function(){
$('.share-btn').on( 'click', fb_share );
});
</script>
This will create a nice popup for sharing to Facebook, and you can easily change the title, description, and picture attributes in the JavaScript. Working demo available here.

Creating IMG Tag With JavaScript, Not Working

Through ArrowChat Javascript API, I'm trying to make avatars show in chat user tabs, that is "on the bar itself", besides in the buddy list and chat window.
I'm editing chat_tab.php (below) for this, starting with a sample static No-Avatar image, and next, I'll try to implement ArrowChat Javascript API functions.
<div class="arrowchat_inner_button" id="chattab_inner">
<div style="float:left" class="arrowchat_username_message">'+shortname+'</div>
</div>
All I want to know for now is that if there's something wrong with this script, as it doesn't seem to work.
Here's the code:
<script type="text/javascript">
window.onload=function(){var elem=document.createElement("elem");
elem.src= "/press/chat/admin/images/img-no-avatar.gif";
elem.height="32"; elem.width="32"; document.getElementById("chattab_inner").appendChild(elem);}
</script>
Next, I should replace img-no-avatar.gif with the user avatar path, which is getUser(data.a) according to the link above. That's the second in the row I don't know how. (You can preview ArrowChat chat bar at the bottom of the screen in the same page.)
The element you are created should be "img" not "elem"
you want the parameter for .createElement() to be the tag name of the element.
<script type="text/javascript">
window.onload=function(){
var elem=document.createElement("img");
elem.src= "/press/chat/admin/images/img-no-avatar.gif";
elem.height="32";
elem.width="32";
document.getElementById("chattab_inner").appendChild(elem);
}
</script>

Twitter Share button dynamic URL share

I'm trying to make a custom Twitter button that will grab the page URL of the current page when clicked, which would obviously change dependent on which page it appears on, not unlike the default share button. However, I am unsure how to pass the page URL into the button.
This is what I have thus far jsfiddle
<style type="text/css" media="screen">
</style>
<div id="social-share-container">
<div id="custom-tweet-button">
<a id="tweetShare" href="https://twitter.com/share?url="+encodeURIComponent(document.URL); target="_blank">Tweet
</a>
</div>
</div>
It's a bit hacked together as I'm pretty unfamiliar with JS.
This passes the url and title to a simple pop-up box with the twitter share page:
<script language="javascript">
function tweetCurrentPage()
{ window.open("https://twitter.com/share?url="+ encodeURIComponent(window.location.href)+"&text="+document.title, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false; }
</script>
<a class="tweet" href="javascript:tweetCurrentPage()" target="_blank" alt="Tweet this page">Tweet this page</a>
If you don't want it to open in a popup box, you can use this instead of window.open:
window.location.href="https://twitter.com/share?url="+ encodeURIComponent(window.location.href)+"&text="+document.title;
Update:
escape() function is deprecated, Replaced with encodeURIComponent()
I would suggest window.location - That will give you the current page url.
Problem is you're using JS inline in HTML - you can't do that like you're wanting to.
I updated your fiddle with some vanilla js to show you a better way to do this.
http://jsfiddle.net/4jF5N/1/
var link = document.getElementById('tweetShare');
var url = window.location;
link.addEventListener('click',function(event){
event.preventDefault();
window.open("https://twitter.com/share?url="+encodeURIComponent(url));
alert(url)
},false);
Take a look on document.location:
location.hostname
location.pathname
http://www.w3schools.com/jsref/obj_location.asp

Categories

Resources