javascript - facebook 和 twitter iframe 请求访问设置 'document.domain' 错误

标签 javascript facebook twitter

我正在将 Tweet 和 Facebook Like 按钮放在我正在工作的项目上。一切似乎都在工作,但是当单击 btns 时,我收到此 JS 错误:

Unsafe JavaScript attempt to access frame with URL http://platform.twitter.com/widgets/tweet_button.1357735024.html#_=1357834238249&count=none&id=twitter-widget-0&lang=en&original_referer=http%3A%2F%2Fwww.sandals.com%2Fmain%2Fnegril%2Fne-home.cfm&size=m&text=Negril%2C%20Jamaica%20All%20Inclusive%20Vacation%20-%20Sandals%20Negril%20Beach%20Resort%20%26%20Spa&url=http%3A%2F%2Fwww.sandals.com%2Fmain%2Fnegril%2Fne-home.cfm&via=SandalsResorts from frame with URL http://www.facebook.com/plugins/like.php?locale=en_US&app_id=150389325070106&href=www.sandals.com/main/negril/ne-home.cfm&send=false&layout=button_count&width=60&show_faces=false&action=like&colorscheme=light&font&height=21. The frame requesting access set 'document.domain' to 'facebook.com', the frame being accessed set it to 'twitter.com'. Both must set 'document.domain' to the same value to allow access.

这是我用于 fb 和 twitter 的代码

window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId      : '150389325070106', // App ID from the App Dashboard
channelUrl : '//www.sandals.com', // Channel File for x-domain communication
status     : false, // check the login status upon init?
cookie     : true, // set sessions cookies to allow your server to access the session?
xfbml      : true,  // parse XFBML tags on this page?
frictionlessRequests: true
});
// Additional initialization code such as adding Event Listeners goes here
};

// Load the SDK's source Asynchronously
(function(d, debug){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));


// Twitter Btn JS
!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="https://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");

我遵循了 fb 开发站点中的步骤,但仍然遇到这些错误:S

最佳答案

正如您在链接的答案中看到的那样,这是 Twitter 的 API 的问题。除了链接问题的答案之外,我还创建了一个自定义推文按钮,它看起来与 Twitter 的 JS API 按钮完全一样,但不使用它,但仍包含分享计数。请随意使用它。

演示:http://fiddle.jshell.net/eyecatchup/Th6P2/2/show/
代码:https://github.com/eyecatchup/tweetbutton

关于javascript - facebook 和 twitter iframe 请求访问设置 'document.domain' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14267864/

相关文章:

ios - iPhone/iPad 商店 ID 区域 - Facebook

ruby-on-rails - 推特照片与推特 gem

javascript - Twitter 在新窗口中分享带有尺寸的链接

javascript - 使用数据表进行高级搜索

facebook - 在 native 桌面应用程序中使用 Facebook 登录

javascript - Jquery下拉列表鼠标离开后不向上滑动

facebook - 为开发目的添加 Facebook 应用程序权限

iOS 11 Twitter 集成客户端解决方法

javascript - xmlHTTPrequest 不会打开 ("GET", url, true);我很生气! PHP

javascript - 定位对应的未经过V8优化的JS代码源