![](/img/trans.png)
[英]Custom Javascript not firing in internet explorer 9 and 10
[英]Facebook Javascript SDK not firing Internet Explorer
首先,我要在Web服務器的端口80上運行此代碼,因此這不是此代碼無法在Internet Explorer上觸發的原因 。
此代碼可在Firefox,Chrome和Safari中完美運行。 但是,當我嘗試使用Internet Explorer運行它時,除了一塊大的空白屏幕外,什么都沒有。
<link rel="stylesheet" type="text/css" href="styles/316127.css" />
<div id="fb-root"></div>
<div class="fb-login-button" data-show-faces="false" data-width="400" data-max-rows="1" scope="email,friends_work_history,friends_location,user_work_history,user_location" id="loginButton" style="display: inherit;"> </div>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
<body>
window.fbAsyncInit = function () {
FB.init({
appId: 'MYAPPID', // App ID
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function (response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
var form = document.createElement("form");
form.setAttribute("method", 'post');
form.setAttribute("action", 'FacebookLogin.ashx');
var field = document.createElement("input");
field.setAttribute("type", "hidden");
field.setAttribute("name", 'accessToken');
field.setAttribute("value", accessToken);
form.appendChild(field);
document.body.appendChild(form);
form.submit();
//display loading logo
document.getElementById('loadinggif').style.display = 'inherit';
document.getElementById('loginButton').style.display = 'none';
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
};
// Load the SDK Asynchronously
(function (d) {
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.js";
ref.parentNode.insertBefore(js, ref);
}(document));
<title>Test</title>
<form id="form1" runat="server">
<br />
<asp:Image ID="loadinggif" runat="server" ImageUrl="~/Site/ajax-loader.gif" ImageAlign="Middle" style="display: none;" CssClass="centered"/>
</form>
`
我剛剛在Internet Explorer 9中打開了它,它運行良好。 我登錄了Facebook,添加了應用程序,然后加載了內容。
您檢查過IE設置了嗎? 確保將其設置為允許javascript。
在這里,同樣的問題我最終做了以下事情:而不是使用:
window.fbAsyncInit = function() {
FB.init({
appId: 'XXXXXX',
status: true,
cookie: true,
xfbml: true
});
}
我使用以下內容:
var fbAsyncLoaded=0;
window.fbAsyncInit = function() {
if(fbAsyncLoaded!=1) { fbAsyncLoaded=1; appInit(); }
}
if(document.addEventListener)
{
document.addEventListener("DOMContentLoaded", function() {
if(fbAsyncLoaded != 1) { fbAsyncLoaded=1; appInit(); }
document.removeEventListener("DOMContentLoaded", arguments.callee, false);
}, false );
} else if(document.attachEvent) {
document.attachEvent("onreadystatechange", function() {
if(document.readyState === "complete") {
if(fbAsyncLoaded != 1) { fbAsyncLoaded=1; appInit(); }
document.detachEvent( "onreadystatechange", arguments.callee);
}
});
}
function appInit()
{
FB.init({
appId: 'XXXXXX',
status: true,
cookie: true,
xfbml: true
});
}
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.