1

我想缩短用 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),
4

0 回答 0