Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > calling javascript function once - from the <body onload="myfunction"> tag

Reply
Thread Tools

calling javascript function once - from the <body onload="myfunction"> tag

 
 
lwhitb1
Guest
Posts: n/a
 
      11-22-2005
I have been trying to load a javascript function from the body onload
html tag, but I only want the function to load the first time the page
is loaded: I have investigated but haven't found anything that works..
I thought about cookies, but what if the user's disable them?


My code:

//I want to call the Toggle function below only on the 1st time the
page is loaded:

<script language="javascript">

function Toggle(item) {

obj=document.getElementById(item);
visible=(obj.style.display!="none")
key=document.getElementById("x" + item);
if (visible) {
obj.style.display="none";


} else {
obj.style.display="block";


}

}


function Expand() {
divs=document.getElementsByTagName("DIV");
for (i=0;i<divs.length;i++) {
divs[i].style.display="block";
key=document.getElementById("x" + divs[i].id);
key.innerHTML="<img src='textfolder.gif' width='175' height='25'
hspace='0' vspace='0' border='0'>";
}
}

function Collapse() {
divs=document.getElementsByTagName("DIV");
for (i=0;i<divs.length;i++) {
divs[i].style.display="none";
key=document.getElementById("x" + divs[i].id);
key.innerHTML="<img src='Button1_01_over.gif' width='179'
height='37' hspace='0' vspace='0' border='0'>";
}
}

</script>

// C# code I inserted above the body tag on my aspx page:

function handler()
{
if(<%=!Page.IsPostBack%> )
{
Toggle('support');
}

}

//The body tag with handler being called:

<body onload="handler()">

FYI: The Toggle('suport); function is not being executed. If i put the
function in the <body onload tag.. it does run..

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      11-22-2005
lwhitb1 wrote on 23 nov 2005 in comp.lang.javascript:

> I have been trying to load a javascript function from the body onload
> html tag, but I only want the function to load the first time the page
> is loaded: I have investigated but haven't found anything that works..
> I thought about cookies, but what if the user's disable them?



What does "only once" mean?

Different users from the same machine?

Same user on different machines?

Same user on different IP and same laptop?

Me seems you should define your quest.

What about having the user log in on your site,
and using a database and serverside script get to your goal.


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
calling javascript function once - from the <body onload="myfunction"> tag lwhitb1 Javascript 1 11-22-2005 11:31 PM
Calling a javascript function from an anchor tag? elsenraat_76@yahoo.com Javascript 5 06-30-2005 01:17 AM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM
calling virtual function results in calling function of base class... Andreas Lagemann C++ 8 01-10-2005 11:03 PM



Advertisments