开发者

Cannot bind click() event to HTML control

开发者 https://www.devze.com 2023-01-08 12:51 出处:网络
Here\'s my setup.I\'m using .NET: I have a Main.aspx lets call it.That page inherits a master page and the Master Page as usual includes the jQuery library and other includes that we use for jQuery

Here's my setup. I'm using .NET:

  1. I have a Main.aspx lets call it. That page inherits a master page and the Master Page as usual includes the jQuery library and other includes that we use for jQuery that are global in scope

  2. In Main.aspx is an HTML plain vanilla IFrame:

  3. In that IFrame is another .aspx page. Lets call it for all tense and purposes Sub.aspx

  4. In Sub.aspx I've got the following code:

<!DOCTYPE html PUBLIC "-//W3C开发者_如何学Go//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <link href="Content/Styles/Site.css" rel="stylesheet" type="text/css" />
        <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
        <div id="facebookPhotos-iFrameContent">
            <div>
                <p id="buttoTestContainer">                    
                    <input type="image" id="btnLogin" src="images/loginBtn.jpg" />
                </p>
            </div>
        </div>
    </form>    
    <script type="text/javascript">    
        var loginButtonID = 'btnLogin';
        //alert(loginButtonID);                   
        window.fbAsyncInit = function () {
            // Initialize/load the JS SDK
            // cookie is set to true to activate JS SDK cookie creation & management
            FB.init({ appId: facebookApplicationID, status: true, cookie: true, xfbml: false });
            alert("got here");
            // also handles the case when they are already logged in
            $('#' + loginButtonID).click(function () {
                alert("login button was fired");
                TestLogin();
            });
            //...rest of code
        });

The problem:

When trying to debug to make sure that .click() event gets called so it binds to my control, I never get to the first alert "got here" so that I know the JS was called at least up to that point. So not sure why. I see absolutely no JS errors in my FireBug console either.


Your function never executes. Remove the window.fbAsyncInit = function() { } and the code will run as interpreted. Or, use $(document).ready(function() { }); to execute it after the DOM is ready.

Also, the Javascript libraries in the parent frame are not inherited by the child. But you can reference them like parent.fbAsyncInit = function() { } or parent.jQuery(); for example.


resolved. That init function should be the only thing in there. Moved all other code outside the window.fbAsyncInit because I do not want to load the others asynchronously, I want to load it after the DOM has completed. The only thing that should be loaded at the same time is the registering/Initialization of that SDK.

0

精彩评论

暂无评论...
验证码 换一张
取 消