我想缩短使用Javascript编写的社交共享按钮的URL。 脚本http://plugins.in1.com/share/demo
社交分享剧本的部分代码
var methods = {
init : function(options) {
this.share.settings = $.extend({}, this.share.defaults, options);
var settings = this.share.settings,
networks = this.share.settings.networks,
theme = this.share.settings.theme,
orientation = this.share.settings.orientation,
affix = this.share.settings.affix,
margin = this.share.settings.margin,
pageTitle = this.share.settings.title||$(document).attr('title'),
pageUrl = this.share.settings.urlToShare||$(location).attr('href'),
pageDesc = "";
$.each($(document).find('meta[name="description"]'),function(idx,item){
pageDesc = $(item).attr("content");
});
// each instance of this plugin
return this.each(function() {
var $element = $(this),
id=$element.attr("id"),
u=encodeURIComponent(pageUrl),
t=encodeURIComponent(pageTitle),
d=pageDesc.substring(0,250),
href;
// append HTML for each network button
for (var item in networks) {
item = networks[item];
href = helpers.networkDefs[item].url;
href = href.replace('|u|',u).replace('|t|',t).replace('|d|',d)
.replace('|140|',t.substring(0,130));
$("<a href='"+href+"' title='Share this page on "+item+
"' class='pop share-"+theme+" share-"+theme+"-"+item+"'></a>")
.appendTo($element);
}
// bind click
$('.pop').click(function(){
window.open($(this).attr('href'),'t','toolbar=0,resizable=1,status=0,width=640,height=528');
return false;
});
});// end plugin instance
}
我的脚本在PHP中执行短片访问页面URL。 用于缩短URL的PHP代码
$short = file_get_contents('http://doma.in/api.php?api=sUio8Sy&url=' . urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
调用PHP代码
$url=json_decode($short,TRUE);
echo $url['short'];
这是在这里做的,但我不确定如何
u=encodeURIComponent(pageUrl),