Posts

Showing posts with the label Javascript

Difference between href="#" and href="javascript:void(0)"

href="" will link to the same page as the one you are currently on, effectively refreshing the page. href="#" will not refresh the page, but using the # will make the screen move to the top of the page (it is the browser effectively looking for an anchor with no name, ). javascript:void(0) will prevent anything happening on the link at all.

Returning Multiple Values in JAVASCRIPT

function myFunction() {   var result = testFunction();    alert(result[0]);//returns "1"    alert(result[1]);//returns "2"    alert(result[2]);//returns "3" } //This function returns multiple values(a,b,c) in the form of array. function  testFunction()  {   var a="1",b="2",c="3";     return [a,b,c] }

Get Query String Using Javascript

To get query string using Javascript: temp = window.location.search.substring(1); document.write( temp ); -We create a variable temp -Built-in Javascript properties:  window.location  is the entire url.  search.substring(1)  is the part after the question mark. -We  write  the value of  temp  to the browser. Below is a  function  that will break the query string into pieces for you: Copy and Paste Javascript Code: <script type="text/javascript"> <!-- function querySt(ji) { hu = window.location.search.substring(1); gy = hu.split("&"); for (i=0;i<gy.length;i++) { ft = gy[i].split("="); if (ft[0] == ji) { return ft[1]; } } } var koko = querySt("koko"); document.write(koko); document.write("<br>"); document.write(hu); --> </script>

Easy Javascript validations.

Click Here

Disable "Right Click" using javascript

Place the below code in Head section of your HTML page <script TYPE="text/javascript"> <!-- //Disable right click script var message="Sorry, right-click has been disabled"; /////////////////////////////////// function clickIE() {if (document.all) {(message);return false;}} function clickNS(e) {if (document.layers||(document.getElementById&&!document.all)) { if (e.which==2||e.which==3) {(message);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>