In HTML code I written script with data-url statically which working fine but my question is how to share link which is generated dynamically?
HTML
<div>
<script type="IN/Share" data-url="http://www.everdrobe.com/rate/551107c763eef/recent" data-counter="top" id="linked_url"></script>
</div>
Linkedin Script
<script src="//platform.linkedin.com/in.js" type="text/javascript"> lang: en_US</script>
I think script executed only once at load time that's why it not working any other way Can I share?
Help should appraciate.
In your js file,
$("#linked_url").click(function() {
window.open("https://www.linkedin.com/shareArticle?mini=true&url="
+ $(this).data("url")
+"&title=",'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
return false;
});
You can share on LinkedIn using a format like so...
https://www.linkedin.com/sharing/share-offsite/?url={url}
Source: Official LinkedIn Sharing Documentation.
So, of course, then you can share in JS dynamically with just...
var yoururl = "yoursite.com?something=somethingelse&test=test2";
$('.share-link').html(
'<a href="' +
'https://www.linkedin.com/sharing/share-offsite/?url=' +
encodeURIComponent(yoururl) +
'">Share on LinkedIn</a>'
);
If you want to prepolulate things like title, description, thumbnail, etc., then check out the OpenGraph tags ase described by the Official LinkedIn Shareable Documentation.
Related
I want to share a link on Facebook after the user has been asked a question on the webpage. The user will be asked "Do you like XYZ". Then, I want to display an option at the bottom of the page to share on Facebook. To share a link on Facebook is
window.open("www.facebook.com/sharer.php?u=window.location.href&t=document.title", "_blank");
and replacing the page's meta description should be something like this?
('meta[property="og:title"]').replaceWith('<meta property="og:title" content="SHARE THIS">');
But I can't seem to combine these into one button.
For instance, the code below is my attempt at doing this and it does not work (absolutely nothing happens).
<button>SHARE</button>
<script type='text/javascript'>
$('button').on('click', function() {
$('meta[property="og:title"]').replaceWith('<meta property="og:title" content={{ result }}>');
$window.open("www.facebook.com/sharer.php?u=http://localhost/&t=document.title", "_blank");
});
</script>
Actually you have a syntax error in you script. window.open doesn't need $ sign.
So, just replace your JS code with mine and it will works if you the correct URL in yor {{ result }}. Please follow below code::
<script type='text/javascript'>
$('button').on('click', function() {
$('meta[property="og:title"]').replaceWith('<meta property="og:title" content={{ result }}>');
window.open("www.facebook.com/sharer.php?u=http://localhost/&t=document.title", "_blank");
});
</script>
Additional Ref::
Window.open syntax
But be carefull, how can you share any localhost URL in FB share, unless and untill it's not on server.
I have a bit of embed code that I need to place on a Google Site, this site will be restricted to our Google domain members. I can place this JavaScript in a Google Gadget and it works fine.
<script type="text/javascript" src='https://HOSTNAME/Forms/js/forms-embed.js?v=9.2'>
</script>
<script type="text/javascript">
var lfembed = new LaserficheForms.Form(null /*element to place form in*/,{bpid: '1', host:'https://HOSTNAME/Forms', params:PARAMS, autoheight: false}).getFrm();
lfembed.style.height = "100%";
</script>
The problem is that I want to be able to get the currently logged in user's email address and pass that in the params: section of the code above.
From what I can tell, you can't do this within a Google Gadget. I can retrieve the current email address with the Google Apps Script object below, but I don't know how to make the two work together.
function doGet() {
var gauser = Session.getActiveUser().getEmail();
var output = ContentService.createTextOutput(gauser);
return output;
}
Another problem is that Google sanitizes some of the JavaScript when I try to include all of the code in just the Google Apps Script.
I really don't have much experience in this area, so if anyone could point me in the right direction I'd appreciate it.
I learned about JSONP today.
I ended up getting this to work by publishing the following Google Apps Script web app.
function doGet(request) {
var gauser = Session.getActiveUser().getEmail();
return ContentService.createTextOutput(
request.parameters.prefix + '(' + JSON.stringify(gauser) + ')')
.setMimeType(ContentService.MimeType.JAVASCRIPT);
}
Then I called the web app service via URL in my XML Gadget
<script src="https://WEBAPPURL?prefix=lfdo"></script>
This placed the username value into the lfdo function, which I inserted into the parameter string I needed it in.
The full Content section of the XML gadget:
<![CDATA[
<script type="text/javascript" src='https://HOSTNAME/Forms/js/forms-embed.js?v=9.2'></script>
<script type="text/javascript">
function lfdo(gauser) {
console.log(gauser);
var lfembed = new LaserficheForms.Form(null /*element to place form in*/,{bpid: '1', host:'https://HOSTNAME/Forms', params:'Name='+ gauser, autoheight: false}).getFrm();
lfembed.style.height = "100%";
gadgets.window.adjustHeight();
}
</script>
<script src="https://WEBAPPURL?prefix=lfdo"></script>
]]>
This article on Google Developers set me in the right direction.
I'm making a small application, and would like to integrate a YouTube section. I have a method of getting the user's YouTube icon:
This in the head:
<script type="text/javascript" src="http://gdata.youtube.com/feeds/api/users/communitychannel?fields=yt:username,media:thumbnail&alt=json-in-script&format=5&callback=showImage"></script>
And this is the script:
<script>
function showImage(data)
{
var name= data.entry.yt$username.$t;
var url = data.entry.media$thumbnail.url;
$(document).append("<img src='"+ url +"'/>");
}
</script>
I'm new with JS, can someone show me how I would now use this to integrate the URL given by the script above into an HTML tag? Thanks.
Hello the $tumbnail returned by youtube is an array, you need to access position 0. Select body to add it.
var url = data.entry.media$thumbnail[0].url;
$('body').append("<img src='"+ url +"'/>");
I have the trio button social media share using Share This API. Everything is ok. They are all sharing right contents. But except for the facebook share image, it cannot be registered as part of the og properties. No image is shown when the facebook popup share shows up. Can someone help please? Thanks in advance!
I actually just followed the template given by client and I dont want to change API/plugin as much as possible. And I cant find any documentation of this kind of service in the API's site http://developer.sharethis.com/.
This is the code.
<script type="text/javascript" src="http://w.sharethis.com/button/sharethis.js#publisher=71dfd17f-04ad-4bd7-acfc-7a47e609cc6f&type=website&post_services=email%2Cfacebook%2Ctwitter&button=false"></script>
<script type="text/javascript">
var BASE_URL = "http://mydemosite.com/";
var shared_object1 = SHARETHIS.addEntry({
title:"My Site | This is showing in fb debugger",
url: BASE_URL,
summary:'My summary. This is showing in fb debugger.',
content:'My Content. This is showing in fb debugger.',
image: BASE_URL + 'share.png'
});
console.log(BASE_URL + 'share.png'); //This returns exactly the url of the image
shared_object1.attachChicklet("email", document.getElementById("share_email"));
shared_object1.attachChicklet("facebook", document.getElementById("share_fb"));
shared_object1.attachChicklet("twitter", document.getElementById("share_twitter"));
</script>
I also checked in facebook's debugger. No image was listed under og: properties.
https://developers.facebook.com/tools/debug
It now worked when I hardcoded also in my <head> tag:
<meta property="og:image" content="<?php echo $base_url; ?>share.png"/>
I need to write a PhoneGap application (with HTML5 and JS, I don't need compatibility with IE) with AJAX so that it reads an RSS feed and looks up some specific information from it. The problem I'm having is that I have I don't the best way to do an RSS feed, and jQuery can't do XML. Any suggestions?
I recently made one using this tutorial : http://net.tutsplus.com/tutorials/javascript-ajax/how-to-build-an-rss-reader-with-jquery-mobile-2/
I have just made a phonegap application that parses an external RSS feed using jFeed. I'll give you an example:
First, I include the following Java scripts in my index.html file:
<head>
...
<script type="text/javascript" src="phonegap-1.0.0.js"></script>
<script type="text/javascript" src="jquery/jquery-1.6.4.js"></script>
<script type="text/javascript" src="jquery.mobile/jquery.mobile-1.0b3.min.js"></script>
<script type="text/javascript" src="jquery.jfeed/dist/jquery.jfeed.js"></script>
<script type="text/javascript" src="scripts/my.js"></script>
...
</head>
Then, in my.js I use the following:
parseFeed();
function parseFeed() {
$.getFeed({
url: 'http://someUrl.com',
dataType: "xml",
success: function(feed) {
$('#feedresult').empty();
var html = '<ul data-role="listview">';
for(var i = 0; i < feed.items.length; i++) {
var item = feed.items[i];
html += '<li>'
+ '<a href="#article?id='
+ i
+ '">'
+ item.title
+ '</a>'
+ '</li>';
}
html = html + '</ul>';
$('#feedresult').append(html);
$('#main').page('destroy').page();
}});
};
The code then creates a listview (jQuery mobile) in my #feedresult div where each entry represents a feed item. As phonegap utilizes some sort of web view that loads all content using the file:/// protocol ( http://groups.google.com/group/phonegap/browse_thread/thread/b60bda03bac6e9eb ), there is no issue in doing cross domain XMLHttpRequest from phonegap.
This question is old, but can be helpful to solve it in 2014 ;-).
I test many jQuery plugin to include a RSS reader, but the only this work like a charme in 1mn is zrssfeed
Just add the call (after call jquery and jquery mobile) in the header:
<script type="text/javascript" src="jquery.zrssfeed.min.js"></script>
And after start th jquery call like this :
<script type="text/javascript">
$(document).ready(function () {
$('#feedresult').rssfeed('http://my.wordpress.website.com/feed/', {
limit: 5
});
});
</script>
I hope this help,
Mike
What You mean jQuery can't do XML. jQuery is JavaScript and jQuery uses XMLHttpRequest while doing Ajax calls. See the name XML*. See: http://api.jquery.com/jQuery.ajax/. There is dataType param. You can pass xml to it. After that You will get dom object with all dom object methods.
You can event use it as second param to jQuery's selectors:
jQuery.get(url, {}, function (data) {
var entries = $("entry", data);
doSomething(entries);
}, 'xml');
One option would be to use a RSS-to-JSON pipe, like this one here: http://pipes.yahoo.com/pipes/pipe.info?_id=2FV68p9G3BGVbc7IdLq02Q