Javascript无法在Facebook应用程序(Iframe)中工作

时间:2013-12-12 16:13:58

标签: javascript html asp.net facebook iframe

嗨我的脚本有问题。我认为它与位置有关...在所有浏览器中都可以正常工作。但是,当此脚本在Facebook应用程序(Iframe)中运行时,它不会在Internet Explorer中触发函数postbackhiddenfield。它在所有其他浏览器中都有...

有人提示吗?

<html xmlns="https://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>      
      <script type="text/javascript">
        // Changing the value of the hidden field forces the page to postback
        // and executes the hdnUpdater_ValueChanged() procedure on the code behind
        function postBackHiddenField(hiddenFieldID) {
            //var hiddenField = $get(hiddenFieldID);
            var hiddenfield = document.getElementById(hiddenFieldID)
            if (hiddenField) {
                hiddenField.value = (new Date()).getTime(); __doPostBack(hiddenFieldID, '');
            }
        }
    </script>

</head>


<body>
    <form id="form1" runat="server">

    <!-- The acess_token is stored...//-->
        <asp:HiddenField ID="hdnAccessToken" runat="server" />
        <!-- The control that postbacks the access_token...//-->
        <asp:HiddenField ID="hdnUpdater" runat="server" />
        <!-- The script that grabs the access_token in the hash, stores the access_token in the
                     'hdnAccessToken', and postbacks the value for JSON retrieval and decoding...//
       window.frameElement.contentWindow.location.hash            
            -->
     <script type="text/javascript">
       if (window.location.hash.length != 0) {              // Check if there's a hash on the URI
        accessToken = window.location.hash.substring(1);    // Retrieve the access_token
        document.getElementById('hdnAccessToken').value = accessToken; // Store the access_token
        //postBackHiddenField('hdnUpdater');                // Postback the page
         __doPostBack('hdnUpdater', '')
         }
        </script>
  </form>
</body>

1 个答案:

答案 0 :(得分:0)

你改变了:document.getElementById(&#39; hdnAccessToken&#39;)。value = accessToken;

document.getElementById('<%= hdnAccessToken.ClientID %>').value = accessToken;