留言板

body onload

thumbnail
sujay paul,修改在11 年前。

body onload

Regular Member 帖子: 164 加入日期: 11-10-28 最近的帖子
Hi,
In an web content i have to write body onload part
how can i do this?

actually i have create a html page which has <BODY onLoad="fillYears(); populateTable(document.dateChooser)" >
part but in web content there is no option for <body> tag is there any other way to do it?

thanks
thumbnail
Tejas Kanani,修改在11 年前。

RE: body onload

Liferay Master 帖子: 654 加入日期: 09-1-6 最近的帖子
Hi Sujay,

As web content display portlet is a part of Liferay page and not a separate page. So ideally there should not be a second <body> tag inside web content. I am not expert of javascript/jQuery but If you want to attached onLoad on main <body> tag, I guess you can do it using javascript/jQuery.

http://stackoverflow.com/questions/1235985/attach-a-body-onload-event-with-js
http://stackoverflow.com/questions/5082165/add-event-handler-for-body-onload-by-javascript-within-body-part

HTH.
thumbnail
Amit Doshi,修改在11 年前。

RE: body onload

Liferay Master 帖子: 550 加入日期: 10-12-29 最近的帖子
Hi Sujay,

I don't know whether it will be a good advice or not.

But I will suggest you, why can't you write directly inside template on the bottom script tag and call that function.

And you will not get Body Tag in any portlet or webcontent. It will be in theme.

But I don't think it is good idea to write on body onload because on every page load it will get called.

So, My suggestion is to write directly inside Velocity template on the bottom with Script tag


<script>
load(); //  function name.
</script>


Hope it helps.

Thanks & Regards,
Amit Doshi
thumbnail
sujay paul,修改在11 年前。

RE: body onload

Regular Member 帖子: 164 加入日期: 11-10-28 最近的帖子
Thanks

but i am sorry
I cant understand the solution

Here is the html code its running properly
I want to put it in web content

<HTML>
<HEAD>
<TITLE>Calendar</TITLE>
<SCRIPT LANGUAGE="JavaScript">
/*******************
UTILITY FUNCTIONS
********************/
// day of week of month's first day
function getFirstDay(theYear, theMonth)
{
var firstDate = new Date(theYear,theMonth,1)
return firstDate.getDay()
}
// number of days in the month
function getMonthLen(theYear, theMonth)
{
var oneDay = 1000 * 60 * 60 * 24
var thisMonth = new Date(theYear, theMonth, 1)
var nextMonth = new Date(theYear, theMonth + 1, 1)
var len = Math.ceil((nextMonth.getTime() - thisMonth.getTime())/oneDay)
return len
}
// create array of English month names
var

theMonths=["January","February","March","April","May","June","July","August","September","October","November","December"]
// return IE4+ or W3C DOM reference for an ID
function getObject(obj)
{
var theObj
if (document.all)
{
if (typeof obj == "string")
{
return document.all(obj)
}
else
{
return obj.style
}
}
if (document.getElementById)
{
if (typeof obj == "string")
{
return document.getElementById(obj)
}
else
{
return obj.style
}
}
return null
}
/************************
DRAW CALENDAR CONTENTS
*************************/
// clear and re-populate table based on form's selections
function populateTable(form)
{
var theMonth = form.chooseMonth.selectedIndex
var theYear = parseInt(form.chooseYear.options[form.chooseYear.selectedIndex].text)
// initialize date-dependent variables
var firstDay = getFirstDay(theYear, theMonth)
var howMany = getMonthLen(theYear, theMonth)
// fill in month/year in table header
getObject("tableHeader").innerHTML = theMonths[theMonth] + " " + theYear
// initialize vars for table creation
var dayCounter = 1
var TBody = getObject("tableBody")
// clear any existing rows
while (TBody.rows.length > 0)
{
TBody.deleteRow(0)
}
var newR, newC
var done=false
while (!done)
{
// create new row at end
newR = TBody.insertRow(TBody.rows.length)
for (var i = 0; i < 7; i++)
{
// create new cell at end of row
newC = newR.insertCell(newR.cells.length)
if (TBody.rows.length == 1 && i < firstDay)
{
// no content for boxes before first day
newC.innerHTML = ""
continue
}
if (dayCounter == howMany)
{
// no more rows after this one
done = true
}
// plug in date (or empty for boxes after last day)
newC.innerHTML = (dayCounter <= howMany) ? dayCounter++ : ""
}
}
}
/*******************
INITIALIZATIONS
********************/
// create dynamic list of year choices
function fillYears()
{
var today = new Date()
var thisYear = today.getFullYear()
var yearChooser = document.dateChooser.chooseYear
for (i = thisYear; i < thisYear + 50; i++)
{
yearChooser.options[yearChooser.options.length] = new Option(i, i)
}
setCurrMonth(today)
}
// set month choice to current month
function setCurrMonth(today)
{
document.dateChooser.chooseMonth.selectedIndex = today.getMonth()
}
</SCRIPT>
</HEAD>
<BODY onLoad="fillYears(); populateTable(document.dateChooser)" >
<H3>Month at a Glance</H3>
<HR>
<TABLE ID="calendarTable" BORDER=1 ALIGN="center" >
<TR>
<TH ID="tableHeader" COLSPAN=7 bgcolor="GREEN"></TH>
</TR>
<TR>
<TH bgcolor="RED">Sun</TH>
<TH bgcolor="RED">Mon</TH>
<TH bgcolor="RED">Tue</TH>
<TH bgcolor="RED">Wed</TH>
<TH bgcolor="RED">Thu</TH>
<TH bgcolor="RED">Fri</TH>
<TH bgcolor="RED">Sat</TH>
</TR>
<TBODY ID="tableBody" bgcolor="BLUE"></TBODY>
<TR>
<TD COLSPAN=7 bgcolor="CYAN">
<P>
<FORM NAME="dateChooser">
<SELECT NAME="chooseMonth" onChange="populateTable(this.form)">
<OPTION SELECTED>January
<OPTION>February
<OPTION>March
<OPTION>April
<OPTION>May
<OPTION>June
<OPTION>July
<OPTION>August
<OPTION>September
<OPTION>October
<OPTION>November
<OPTION>December
</SELECT>
<SELECT NAME="chooseYear" onChange="populateTable(this.form)">
</SELECT>
</FORM>
</P>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

Please help me what should i write in web content?

Thanks