You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by andy wix <st...@hotmail.com> on 2004/11/18 13:37:52 UTC
Tiles and on-load events
Hi,
I have a page which I would like frequently reloaded into the browser and
was going to use javascript. The issue is that using Tiles I only have the
on-load event available for the layout.jsp file and I only want one of my
pages to have this functionality.
Is there a work-around?
Thanks,
Andy
_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Tiles and on-load events
Posted by Joe Germuska <Jo...@Germuska.com>.
At 12:37 PM +0000 11/18/04, andy wix wrote:
>Hi,
>
>I have a page which I would like frequently reloaded into the
>browser and was going to use javascript. The issue is that using
>Tiles I only have the on-load event available for the layout.jsp
>file and I only want one of my pages to have this functionality.
>
>Is there a work-around?
Here is the simplest thing I've found, from Simon Willison:
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
full writeup at: http://www.sitepoint.com/blog-post-view.php?id=171578
It wouldn't be too hard to extend this so that you could use one
function to add both onload and onunload events, should that be
valuable. In this case, you don't even specify an onload attribute
in your <html> tag. If you do, it would override anything set using
this mechanism.
Joe
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction" -The Ex
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Tiles and on-load events
Posted by da...@exemel.co.uk.
I had a similar problem.
I included a piece of Javascript in the main layout which allows pages
to register
script to be run when onload is invoked, then any page in the layout can
add things:
<html>
<head>
<script language="JavaScript">
var onLoadExpressions = new Array();
var onUnLoadExpressions = new Array();
function addOnLoadExpression(expr, checkForDuplicates)
{
if (checkForDuplicates && findOnLoadExpression(expr))
{
return;
}
var newExprs = new Array(onLoadExpressions.length + 1);
var i;
for (i=0; i<onLoadExpressions.length; i++)
{
newExprs[i] = onLoadExpressions[i];
}
newExprs[onLoadExpressions.length] = expr;
onLoadExpressions = newExprs;
}
function addOnUnLoadExpression(expr, checkForDuplicates)
{
if (checkForDuplicates && findOnUnLoadExpression(expr))
{
return;
}
var newExprs = new Array(onUnLoadExpressions.length + 1);
var i;
for (i=0; i<onUnLoadExpressions.length; i++)
{
newExprs[i] = onUnLoadExpressions[i];
}
newExprs[onUnLoadExpressions.length] = expr;
onUnLoadExpressions = newExprs;
}
function findOnLoadExpression(expr)
{
var exprFound = false;
var i;
for (i=0; i<onLoadExpressions.length; i++)
{
if (expr == onLoadExpressions[i])
{
exprFound = true;
}
}
return exprFound;
}
function findOnUnLoadExpression(expr)
{
var exprFound = false;
var i;
for (i=0; i<onUnLoadExpressions.length; i++)
{
if (expr == onUnLoadExpressions[i])
{
exprFound = true;
}
}
return exprFound;
}
function documentLoaded()
{
var i;
for (i=0; i<onLoadExpressions.length; i++)
{
eval(onLoadExpressions[i]);
}
}
function documentUnLoaded()
{
var i;
for (i=0; i<onUnLoadExpressions.length; i++)
{
eval(onUnLoadExpressions[i]);
}
}
</script>
</head>
<body onload="documentLoaded();" onunload="documentUnLoaded();">
</body>
</html>
then in your jsp just use:
<script>
addOnLoadExpression('alert("hello");', false);
</script>
Dave
> -----Original Message-----
> From: andy wix [mailto:stixwix@hotmail.com]
> Sent: Donnerstag, 18. November 2004 12:38
> To: user@struts.apache.org
> Subject: Tiles and on-load events
>
>
> Hi,
>
> I have a page which I would like frequently reloaded into the
> browser and
> was going to use javascript. The issue is that using Tiles I
> only have the
> on-load event available for the layout.jsp file and I only
> want one of my
> pages to have this functionality.
>
> Is there a work-around?
>
> Thanks,
> Andy
>
> _________________________________________________________________
> It's fast, it's easy and it's free. Get MSN Messenger today!
> http://www.msn.co.uk/messenger
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org