【问题标题】:facebook and twitter iframes requesting access set 'document.domain' errorfacebook 和 twitter iframe 请求访问集“document.domain”错误
【发布时间】:2012-12-25 10:15:14
【问题描述】:

我正在将 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

【问题讨论】:

标签: javascript facebook twitter


【解决方案1】:

正如您在链接的答案中看到的,这是 Twitter API 的问题。作为链接问题的答案的替代方案,我创建了一个自定义推文按钮,该按钮看起来与 Twitter 的 JS API 完全相同,但不使用它,但仍包含共享计数。随意使用。

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

【讨论】:

猜你喜欢
  • 2018-02-13
  • 1970-01-01
  • 2013-02-06
  • 2014-09-29
  • 1970-01-01
  • 2019-09-16
  • 2011-07-18
  • 2020-12-06
  • 2021-09-07
相关资源
最近更新 更多