2016-07-09 4 views
0

Facebook上でパラメータを持つページを共有しようとするときに問題が発生しています。これは私が使用しているコードです: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); 
} 

とURLは次のとおりです。

二つのパラメータ実際には存在し
https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2127.0.0.1%3A50846%2FIndex.html%3Faction%3DDO1%26param%3D4cf13a1311fe40afa401b25ef7fa0379f1f7c1930a04f8755d678474d0c30e0c 

  1. アクション= DO1は、と
  2. param = 4cf13a1311fe40afa401b25ef7fa0379f1f7c1930a04f8755d678474d0c30e0c

最初は共有URLをエンコードしませんでした(つまり、=,/,&文字を使用していました)、共有は機能しましたが、パラメータが欠落していました。エンコードされたURLを入力すると、Facebookのウィンドウがポップアップしますが、すぐに消えます。

URLをパラメータと共有するにはどうすればいいですか?フィード共有メカニズムに切り替える必要はありませんか?

ありがとうございます。

+0

なぜローカルホストのURLを共有したいですか?それは意味をなさない... – luschn

+0

私は現在、テスト環境で作業しています。私が今見たいのは、Facebookの株式ポストに埋め込まれているリンクが正しいことだけです。必要に応じて機能すると、URLは実際の値に修正されます。 – FDavidov

+0

ローカルホストではなく、公開URLで試してみてください。あなたはそのようにそれをテストすることはできません。 – luschn

答えて

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); 
}; 

、それは魔法のように動作します!

関連する問題