if(typeof self.cnt != 'number')cnt = sum;
return cnt;
};
the value that is returned remains static in javascript
Labels: Javascript
Labels: Interview Questions, Javascript
Labels: Javascript
There are hundreds of way of writing OO javascript, I tried a lot of the most commons and I finally adopted one : oo using prototypes.
Labels: Javascript
Javascript is using prototypes and is the only language I know that is doing it. What is the idea behind it? Simple. With prototypes, you can extend (add methods/properties) any class you want anywhere you want anytime you want even if you are not the owner of that object. Object-oriented purist will be shocked but I am more than pleased with that.
Labels: Javascript
There are hundreds of ways to do inheritance in javascript but a single one is simpler, cleanier and prettier than all the other ones.
Labels: Javascript
Labels: Javascript
Labels: ExtJS, Javascript
Labels: Javascript
Math.round(25.9) //returns 26 Math.round(25.2) //returns 25 Math.round(-2.58) //returns -3
var original=28.453
1) //round "original" to two decimals var result=Math.round(original*100)/100 //returns 28.45
2) // round "original" to 1 decimal var result=Math.round(original*10)/10 //returns 28.5
3) //round 8.111111 to 3 decimals var result=Math.round(8.111111*1000)/1000 //returns 8.111
Labels: Javascript
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
<style type="text/css">
table { page-break-inside:auto }
tr { page-break-inside:avoid; page-break-after:auto }
thead { display:table-header-group }
tfoot { display:table-footer-group }
</style>
</head>
<body>
<table>
<thead>
<tr><th>heading</th></tr>
</thead>
<tfoot>
<tr><td>notes</td></tr>
</tfoot>
<tr>
<td>x</td>
</tr>
<tr>
<td>x</td>
</tr>
<!-- 500 more rows -->
<tr>
<td>x</td>
</tr>
</tbody>
</table>
</body>
</html>
Note
<style>
@media print
{
table {page-break-after:always}
}
</style>
Click here to View more...
Labels: Javascript
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<title>JavaScript printing</title>
<script type="text/javascript">
var win=null;
function printIt(printThis)
{
win = window.open();
self.focus();
win.document.open();
win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
win.document.write(printThis);
win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
win.document.close();
win.print();
win.close();
}
</script>
</head>
<body>
<a href="#" onclick="printIt(document.getElementById('printme').innerHTML); return false">
Print
</a>
<br />
<div id="printme">Only this part of the page is printed</div>
</body>
</html>
Click here to View more...
Labels: Javascript
A print stylesheet formats a web page so when printed, it automatically prints in a user-friendly format. Print stylesheets have been around for a number of years and have been written about a lot. Yet so few websites implement them, meaning we're left with web pages that frustratingly don't properly print on to paper.
It's remarkable that so few websites use print stylesheets as:
<link rel="stylesheet" href="print.css" type="text/css" media="print" />
class="noprint" in the HTML. To get rid of these items, along with the header and navigation (assuming these are assigned div id="header" and div id="nav") use the display: none command:#header, #nav, .noprint {display: none;}width: 100%; margin: 0; float: none;div for a CSS layout and table for table layouts) to ensure the content spans the full width of the paper. So, the full CSS command would perhaps be something like:#container, #container2, #content {width: 100%; margin: 0; float: none;}a:link, a:visited {color: #781351} /* Remove unwanted elements */
#header, #nav, .noprint
{
display: none;
}
/* Ensure the content spans the full width */
#container, #container2, #content
{
width: 100%; margin: 0; float: none;
}
/* Change text colour to black (useful for light text on a dark background) */
.lighttext
{
color: #000
}
/* Improve colour contrast of links */
a:link, a:visited
{
color: #781351
}
Labels: Javascript
The following code creates a hyperlink and uses the Javascript print function to print the current page:
<a href="JavaScript:window.print();">Print this page</a>
function PrintContent() { var DocumentContainer = document.getElementById('historyListPanel'); var WindowObject = window.open('',"TrackHistoryData", "width=740,height=325,top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no"); WindowObject.document.writeln(DocumentContainer.innerHTML); WindowObject.document.close(); WindowObject.focus(); WindowObject.print(); WindowObject.close(); }
pass your table id or div id or contentid
Labels: Javascript
onclick="if (!confirm('Are you sure you want to continue?')) {return false;}" Click here to View more...
Labels: Interview Questions, Javascript