Tech Sharing Blog

Computer knowledge, news, product, SEO, earn money online sharing place

Advertisement

Posts Tagged ‘ Javascript ’

Just come across with my company SQA team where they request us to do the disable right click features on our front end web site. The initial javascript which exists in our script only work with Microsoft Internet Explorer but not Firefox.

So Google around and found the following javascript which working for both the browser (Firefox and Internet Explorer are the major browser use by our visitor)

Just include this script in our top of the page which you wish to disable the right click function.

<script type="text/javascript">

function md(e)
{
  try { if (event.button==2||event.button==3) return false; }
  catch (e) { if (e.which == 3) return false; }
}
document.oncontextmenu = function() { return false; }
document.ondragstart   = function() { return false; }
document.onmousedown   = md;

</script>

Popularity: 1% [?]

the following example use the javascript regular express to validate the value where Chinese charecter is not allow.


<script   language=javascript>   
    
  function   checkChinese(){   
    
      var   re   =   /[\u4E00-\u9FA0]+/;   
    
      if   (re.test(form1.tjiccode.value))   
    
      {   
    
          alert(“不允许输入中文!”);   
    
  return   false;   
    
      }   
    
  }   

Popularity: 1% [?]

Check the page’s last update date

  1. Go to any web site as you like
  2. Delete the content in the URL address bar
  3. Enter the following script javascript:alert(document.lastModified)
  4. Press Enter
  5. This code will display any web page’s last update including the specific time, so by using the this script, you will know that the content you get is that the latest or not

tech share latest update URL Hidden Tricks to check pages last update

Tech share latest update is 11 Oct 2009 16:36:23


Popularity: 1% [?]

Most of the developer who working in MS platform will be used to the javascript window.attachEvent.


But maybe some of you don’t know that window.attachEvent is only working on IE7+ and Opera only. Your coding will hit an javascrpit error when running at IE 6 or any version of firefox.


To resolve this issue, you may need to modify your code as such:

Original Code:

window.attachEvent(“onload”, Page_load);

function Page_load(){
//function code
}


Modify code:

//set page event handlers
if (window.attachEvent) {

//IE and Opera
window.attachEvent(“onload”, Page_load);

} else if (window.addEventListener) {

// IE 6
window.addEventListener(“load”, Page_Unload, false);

} else {

//FireFox
document.addEventListener(“load”, Page_Unload, false);

}

function Page_load(){

//function code

}


Popularity: 1% [?]

There is always the good way to prevent and verify the using enter data, especially for each text box or text area.


The following is script use the event object to check on the key code that the user enter, return false to prevent user to enter.


Disabled space to be enter in javascript

onKeypress=”if (event.keyCode == 32) event.returnValue = false;”


Sample:


Only allow number and . to be enter in javascript

onkeypress=”if (event.keyCode < 47 || event.keyCode /> 57) event.returnValue = false;”


Sample:

Popularity: 1% [?]

Trim a string in Javascript

By on June 13, 2009


Trim is a good features when you try to delete the space at the left most, right most or both the left most and right most of the string. The following trim function is ultilize the javascript Regular expression for the trim function


Left Trim

function ltrim(str){

    return str.replace(/^\s+/, ”);

}


Right Trim

function rtrim(str) {

    return str.replace(/\s+$/, ”);

}


All trim

function alltrim(str) {

    return str.replace(/^\s+|\s+$/g, ”);

}


Popularity: 1% [?]

SEO Powered by Platinum SEO from Techblissonline