Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. document.ready() and window.load() events don't fire

document.ready() and window.load() events don't fire

Scheduled Pinned Locked Moved JavaScript
questionjavascripthelp
10 Posts 6 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    benams
    wrote on last edited by
    #1

    I try to execute this code(I place it between the head tags):

    $(document).ready(function () {
    alert("document ready occurred!");
    });

        $(window).load(function () {
            alert("window load occurred!");
        });
    

    none of the functions is executed and I can't see any message box. What can be the reason and how can I fix it? *I have references to the jquery libary in the page's master.

    N D M A 5 Replies Last reply
    0
    • B benams

      I try to execute this code(I place it between the head tags):

      $(document).ready(function () {
      alert("document ready occurred!");
      });

          $(window).load(function () {
              alert("window load occurred!");
          });
      

      none of the functions is executed and I can't see any message box. What can be the reason and how can I fix it? *I have references to the jquery libary in the page's master.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Have you placed in inside script tags?

      <script>
      $(document).ready(function () {
      alert("document ready occurred!");
      });

          $(window).load(function () {
              alert("window load occurred!");
          });
      

      </script>


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • B benams

        I try to execute this code(I place it between the head tags):

        $(document).ready(function () {
        alert("document ready occurred!");
        });

            $(window).load(function () {
                alert("window load occurred!");
            });
        

        none of the functions is executed and I can't see any message box. What can be the reason and how can I fix it? *I have references to the jquery libary in the page's master.

        D Offline
        D Offline
        DaveAuld
        wrote on last edited by
        #3

        If you are using master pages, then the page you are running the script on doesn't have a head section???? have you tried placing the script at the beginning on the content block in a set of script tags?

        Dave Find Me On: Web|Facebook|Twitter|LinkedIn


        Folding Stats: Team CodeProject

        1 Reply Last reply
        0
        • B benams

          I try to execute this code(I place it between the head tags):

          $(document).ready(function () {
          alert("document ready occurred!");
          });

              $(window).load(function () {
                  alert("window load occurred!");
              });
          

          none of the functions is executed and I can't see any message box. What can be the reason and how can I fix it? *I have references to the jquery libary in the page's master.

          D Offline
          D Offline
          DaveAuld
          wrote on last edited by
          #4

          Well, the code you have listed works fine; I have just set up a fresh asp.net project and this works fine when the code is placed in a script block with the HeadContent content block as shown below; Master Page

          <%@ Master Language="VB" AutoEventWireup="false" CodeFile="Site.Master.vb" Inherits="Site" %>

          <!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" xml:lang="en">
          <head runat="server">
          <title></title>
          <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
          <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
          <asp:ContentPlaceHolder ID="HeadContent" runat="server">

          </asp:ContentPlaceHolder>
          

          </head>
          <body>
          <form runat="server">
          <div class="page">
          <div class="header">
          <div class="title">
          <h1>
          My ASP.NET Application
          </h1>
          </div>
          <div class="loginDisplay">
          <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
          <AnonymousTemplate>
          [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
          </AnonymousTemplate>
          <LoggedInTemplate>
          Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
          [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
          </LoggedInTemplate>
          </asp:LoginView>
          </div>
          <div class="clear hideSkiplink">
          <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
          <Items>
          <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
          <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
          <asp:MenuItem NavigateUrl="~/Default2.aspx" Text="Default2" Value="Default2">
          </asp:MenuItem>
          </Items>

          B 1 Reply Last reply
          0
          • D DaveAuld

            Well, the code you have listed works fine; I have just set up a fresh asp.net project and this works fine when the code is placed in a script block with the HeadContent content block as shown below; Master Page

            <%@ Master Language="VB" AutoEventWireup="false" CodeFile="Site.Master.vb" Inherits="Site" %>

            <!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" xml:lang="en">
            <head runat="server">
            <title></title>
            <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
            <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
            <asp:ContentPlaceHolder ID="HeadContent" runat="server">

            </asp:ContentPlaceHolder>
            

            </head>
            <body>
            <form runat="server">
            <div class="page">
            <div class="header">
            <div class="title">
            <h1>
            My ASP.NET Application
            </h1>
            </div>
            <div class="loginDisplay">
            <asp:LoginView ID="HeadLoginView" runat="server" EnableViewState="false">
            <AnonymousTemplate>
            [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
            </AnonymousTemplate>
            <LoggedInTemplate>
            Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /></span>!
            [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/"/> ]
            </LoggedInTemplate>
            </asp:LoginView>
            </div>
            <div class="clear hideSkiplink">
            <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
            <Items>
            <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
            <asp:MenuItem NavigateUrl="~/About.aspx" Text="About"/>
            <asp:MenuItem NavigateUrl="~/Default2.aspx" Text="Default2" Value="Default2">
            </asp:MenuItem>
            </Items>

            B Offline
            B Offline
            benams
            wrote on last edited by
            #5

            it's exactly what I did and it still doesn't work...

            1 Reply Last reply
            0
            • B benams

              I try to execute this code(I place it between the head tags):

              $(document).ready(function () {
              alert("document ready occurred!");
              });

                  $(window).load(function () {
                      alert("window load occurred!");
                  });
              

              none of the functions is executed and I can't see any message box. What can be the reason and how can I fix it? *I have references to the jquery libary in the page's master.

              M Offline
              M Offline
              Monjurul Habib
              wrote on last edited by
              #6

              To include in your web app, cut-and-paste(replace

              ) with

              If it works then your jQuery path is not ok. Please let me know your result.

              modified on Tuesday, June 21, 2011 6:25 PM

              1 Reply Last reply
              0
              • B benams

                I try to execute this code(I place it between the head tags):

                $(document).ready(function () {
                alert("document ready occurred!");
                });

                    $(window).load(function () {
                        alert("window load occurred!");
                    });
                

                none of the functions is executed and I can't see any message box. What can be the reason and how can I fix it? *I have references to the jquery libary in the page's master.

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #7

                A few notes / ideas:

                • Do not self-close your script tags when you include jQuery:

                  <!-- Good -->
                  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
                  <!-- Bad -->
                  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"/>

                • Be sure your proxy is not preventing jQuery from loading. Also, your browser may not want to load a local copy of jQuery.

                • Ensure you include jQuery before you run your script.

                • benams wrote:

                  I place it between the head tags

                  That makes me think you aren't using a script tag. Your script should be included in a script tag, the "type" should be set to "text/javascript", and the "language" should be set to "javascript". Also ensure you do NOT have runat="server" on your script tag.

                • Do not include your above JavaScript in the same script block you use to include jQuery.

                • Try running a simple alert("hello"); without including jQuery, just to see if your JavaScript is running.

                • View the source of your page to be sure the rendered HTML is correct.

                • What works in one browser may not work in another. Try using different browsers.

                • If you could include your ENTIRE page, that would be of use.

                Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

                V 1 Reply Last reply
                0
                • A AspDotNetDev

                  A few notes / ideas:

                  • Do not self-close your script tags when you include jQuery:

                    <!-- Good -->
                    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
                    <!-- Bad -->
                    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"/>

                  • Be sure your proxy is not preventing jQuery from loading. Also, your browser may not want to load a local copy of jQuery.

                  • Ensure you include jQuery before you run your script.

                  • benams wrote:

                    I place it between the head tags

                    That makes me think you aren't using a script tag. Your script should be included in a script tag, the "type" should be set to "text/javascript", and the "language" should be set to "javascript". Also ensure you do NOT have runat="server" on your script tag.

                  • Do not include your above JavaScript in the same script block you use to include jQuery.

                  • Try running a simple alert("hello"); without including jQuery, just to see if your JavaScript is running.

                  • View the source of your page to be sure the rendered HTML is correct.

                  • What works in one browser may not work in another. Try using different browsers.

                  • If you could include your ENTIRE page, that would be of use.

                  Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

                  V Offline
                  V Offline
                  vbmike
                  wrote on last edited by
                  #8

                  Just as a side question to this reply: I was wondering why you said NOT to self-close the script tag? Is that particular to asp pages or a certain DOCTYPE or anything to do with jquery. I am just learning and have not seen that mentioned before....thanks.

                  michael judy vbmike@hotmail.com "He's ALIVE, Jim. Where did I go wrong?"

                  A 1 Reply Last reply
                  0
                  • V vbmike

                    Just as a side question to this reply: I was wondering why you said NOT to self-close the script tag? Is that particular to asp pages or a certain DOCTYPE or anything to do with jquery. I am just learning and have not seen that mentioned before....thanks.

                    michael judy vbmike@hotmail.com "He's ALIVE, Jim. Where did I go wrong?"

                    A Offline
                    A Offline
                    AspDotNetDev
                    wrote on last edited by
                    #9

                    That will not work in some browsers. It's a problem I've run into before. See here: JavaScript Function Not Called When Defined in External ".JS" File.

                    Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

                    V 1 Reply Last reply
                    0
                    • A AspDotNetDev

                      That will not work in some browsers. It's a problem I've run into before. See here: JavaScript Function Not Called When Defined in External ".JS" File.

                      Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.

                      V Offline
                      V Offline
                      vbmike
                      wrote on last edited by
                      #10

                      Ok, thanks, I'll keep an eye out. I always try and test in all the major browsers before release so hopefully I will catch things like this. MJ michael judy vbmike@hotmail.com "He's ALIVE, Jim. Where did I go wrong?"

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups