简体   繁体   English

javascript在ie8中不起作用

[英]javascript is not working in ie8

I have used a fb script to increase a size of canvas. 我使用了一个fb脚本来增加画布的大小。 Here is the code.. 这是代码..

<div id="fb-root"></div>

<script type="text/javascript">
    window.fbAsyncInit = function () {
        FB.init({ appId: '171963559525911', status: true, cookie: true, xfbml: true });
        FB.Canvas.setSize({ width: 1500, height: 1500 });
    };

    (function () {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol +
                    '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
    } ());
</script>

<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>

It is working in all browsers I've tested except IE8. 除了IE8之外,它在我测试的所有浏览器中都有效。 In fact also working in IE9 but not working in IE8. 实际上也在IE9中工作但不在IE8中工作。

Please suggest me to solve the issue. 请建议我解决这个问题。

Thanks 谢谢

This is what I use for extending the size of my canvas and it works in all browsers: 这是我用于扩展画布大小的方法,它适用于所有浏览器:

<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>
<script type="text/javascript">
    FB_RequireFeatures(["CanvasUtil"], function()
    {
      FB.XdComm.Server.init("/xd_receiver.htm?v=2");
      FB.CanvasClient.startTimerToSizeToContent();
    });
    function onWindowResized(info)
    {
      var canvasInfoDiv = document.getElementById("CanvasInfo");
      var text = String.format("window ({0}, {1}), page ({2}, {3}), canvas({4}, {5}), scrollPos({6}, {7}), canvasPos({8}, {9})", 
        info.window.w, info.window.h,info.page.w, info.page.h,
        info.canvas.w, info.canvas.h,
        info.scrollPos.x, info.scrollPos.y,
        info.canvasPos.x, info.canvasPos.y);
      canvasInfoDiv.innerHTML = text;
    }
</script>

You need to have the xd_receiver.htm inside of a publicly accessibly directory as well. 您还需要在公共可访问目录中包含xd_receiver.htm。 Here is the contents of that file: 这是该文件的内容:

xd_receiver.htm xd_receiver.htm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>cross domain receiver page</title>
</head>
<body>
    <script src="http://static.ak.facebook.com/js/api_lib/v0.4/XdCommReceiver.js?2" type="text/javascript"></script>
</body>
</html>

EDIT: 编辑:

$(document).ready(function(){
  FB.init({appId:'your-app-id', status:true, cookie:true, xfbml:true});
  $(window).load(function(){
    FB.Canvas.setSize({height:1100});
  });
});

Obviously set the height to whatever the height of your content is. 显然,将高度设置为内容的高度。 Before I had: 在我之前:

FB.Canvas.setSize({height:$('html').height()});

But IE seems to not like that. 但IE似乎不喜欢这样。 Shouldn't have to explicitly set the height #, but had to in this case. 不应该明确设置高度#,但在这种情况下不得不这样做。

Lets try this one: 让我们尝试这个:


$.ajax({

  url: document.location.protocol +'/connect.facebook.net/en_US/all.js',

  dataType: 'script',

  success: function(){//do anything ...}

});
(function () {
        //doing stuff
    } ());

should be 应该

(function () {
        //doing stuff
    })();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM