2016-07-09 5 views
0

Facebook에서 매개 변수가있는 페이지를 공유하는 데 문제가 있습니다. 이것은 내가 사용하고 코드입니다 :Facebook Twitter에서 "swallowing"매개 변수가 사라 지거나 사라졌습니다.

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

localhost가 아닌 공개 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); 
}; 

하고 그것이 마치 마법처럼 작동합니다!