Tech Sharing Blog

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

Advertisement

Archive for the ‘ Javascript ’ Category

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% [?]

SQLInjection1 1 Possible injection use keyword

All the web developer, web admin, as well as DB admin are always facing the attacking from all around the world toward their web site, but how to prevent it?


Some may use the 3th party software to prevent it, some may just filter all the possible keyword enter by the user, some will use the database store procedure to prevent it. The following are some of the keyword that you may need to take care of when you allow your user to enter any input to your system.


Web site injection attack keyword (204)

Popularity: 4% [?]

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% [?]

SEO Powered by Platinum SEO from Techblissonline