Category Archives: Javascript

How to block right click on a page

<script language=”JavaScript”>

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”)

</script>

Load page content based on menu using simple javascript

Here i have used a javascript function that will display blcok based on the menu that you clicked .
Paste the below given code in  page and load that so as to get a better idea of how it works . 

<script type=”text/javascript”>
function NextPage($pageID){
for($i=1;$i<=3;$i++){
if(Number($i)==Number($pageID))
document.getElementById(“page”+$i).style.display=’block’
else
document.getElementById(“page”+$i).style.display=’none’
}
}
</script>
<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>
<div id=”page1″ style=”display:block”>
<strong> Page 1</strong> <br>
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).

</div>

<div id=”page2″ style=”display:none”>
<strong> Page 2</strong> <br>
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).

</div>

<div id=”page3″ style=”display:none”>
<strong> Page 3</strong> <br>
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).

</div>
</td>
</tr>
</table>

switch statement – Javascript

<script type=”text/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;

}

</script>
<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>