Facebook分享"吞咽"参数或消失

时间:2016-07-09 08:30:29

标签: facebook facebook-sharer

我在尝试与Facebook上的参数共享页面时遇到了麻烦。这是我使用的代码:

function PopupCenter(url, title, w, h) {
    var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
    var dualScreenTop  = window.screenTop != undefined ? window.screenTop : screen.top;
    var width  = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth  ? document.documentElement.clientWidth  : screen.width ;
    var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
    var left = ((width / 2) - (w / 2)) + dualScreenLeft ;
    var top = ((height / 2) - (h / 2)) + dualScreenTop  ;
    var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
}

,网址为:

https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2127.0.0.1%3A50846%2FIndex.html%3Faction%3DDO1%26param%3D4cf13a1311fe40afa401b25ef7fa0379f1f7c1930a04f8755d678474d0c30e0c

其中有两个参数:

  1. action = DO1,
  2. PARAM = 4cf13a1311fe40afa401b25ef7fa0379f1f7c1930a04f8755d678474d0c30e0c
  3. 最初,我没有编码共享网址(意思是,使用=/&个字符)并且共享工作但参数丢失了。现在我输入了一个编码的URL,Facebook的窗口会弹出,但会立即消失。

    有人可以告诉我如何设置共享带参数的网址 是否需要切换到Feed共享机制?

    提前致谢。

1 个答案:

答案 0 :(得分:0)

我使用 encodeURIComponent 方法找到了解决方案,所以现在我的功能是:

function PopupCenter(url, title, w, h) {
    var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
    var dualScreenTop  = window.screenTop != undefined ? window.screenTop : screen.top;
    var width  = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth  ? document.documentElement.clientWidth  : screen.width ;
    var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
    var left = ((width / 2) - (w / 2)) + dualScreenLeft ;
    var top = ((height / 2) - (h / 2)) + dualScreenTop  ;
    var newWindow = window.open(encodeURIComponent(url), title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
};

它就像一个魅力!!