document.ready() and window.load() events don't fire
-
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.
-
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.
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
-
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.
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
-
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.
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> -
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> -
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.
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
-
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 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.
-
-
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.
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?"
-
-
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?"
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.
-
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.
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?"