<a href=”javascript:window.print()”>Print</a>
Category Archives: Javascript
Check javascript is enabled in the browser + php
<noscript>Please enable Javascript</noscript>
javascript load a url in new tab
javascript:window.open(‘www.example.oom’,’_blank’)
How to block right click on a page
function clickIE() {
if (document.all) {alert(“Right Click Not Allowed”);return false;}}function clickNS(e) {
if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {alert(“Right Click Not Allowed”);return false;}}}
if (document.layers) {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}document.oncontextmenu=new Function(“return false”)
Load page content based on menu using simple javascript
Paste the below given code in page and load that so as to get a better idea of how it works .
function NextPage($pageID){
for($i=1;$i
<table>
<tr>
<td>
<a href=”javascript:NextPage(‘1’);”>Page1</a>
<a href=”javascript:NextPage(‘2’);”>Page2</a>
<a href=”javascript:NextPage(‘3’);”>Page3</a>
</td>
<td>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using ‘Content here, content here’, making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for ‘lorem ipsum’ will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</td>
</tr>
</table>
Get current site URL – Javascript
alert( document.URL );
How to check if a Javascript function exists
function myFunction() {
}
if(window.myFunction) {
alert(“‘myFunction’ already exists”);
} else {
alert(“‘myFunction’ does not already exists”);
}
switch statement – Javascript
function displaySize(sizes){
switch (sizes) {
case “header”:sizeDim=’728 x 90′;break;
case “footer”:sizeDim=’500 x 150′;break;
case “sidebar”:sizeDim=’7263 x 181′;break;
}
document.getElementById(‘dimension’).innerHTML=sizeDim;
}
<table>
<tr>
<td>Select Position</td> <td>
<select name=”banner_position” onchange=”javascript:displaySize(this.value);”>
<option value=”>Select the position</option>
<option value=’header’ >Header</option>
<option value=’footer’ >Footer</option>
<option value=’sidebar’ >Sidebar</option>
</select>
</td>
</tr>
<tr>
<td>Upload image</td> <td> <input type=”file” name=”image” />(Size should be <span id=”dimension”></span>) </td>
</tr>
</table>
Scrollers – Javascript
Follow the below given link
The number of elements in a Javascript array
eg :
var str = new Array(“First element”, “Second”, “Last”);
alert(str.length) //will return the number of elements in an array