Visualizzazione post con etichetta Javascript / AJAX. Mostra tutti i post
Visualizzazione post con etichetta Javascript / AJAX. Mostra tutti i post

venerdì 7 marzo 2008

Disable Ctrl-N

Here is a simple way to disable CTRL-N in Javascript.



document.onkeydown = function(){
if ((event.keyCode == 78) && (event.ctrlKey)){
//alert ("No new window")
event.cancelBubble = true;
event.returnValue = false;
event.keyCode = false;
return false;
}
}

No right click

Here is a simple way to disable right-click in Javascript.



var message="";
///////////////////////////////////
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")

mercoledì 5 marzo 2008

JSON

JSON (JavaScript Object Notation) is a format used for transmitting structured data over a network connection in a process called serialization. Its main application is in Ajax web application programming, where it serves as an alternative to the traditional use of XML.


JSON's basic types are
  • Number (integer, real, or floating point)
  • String (double-quoted Unicode with backslash escapement)
  • Boolean (true and false)
  • Array (an ordered sequence of values, comma-separated and enclosed in square brackets)
  • Object (collection of key/value pairs, comma-separated and enclosed in curly brackets)
  • null


The following example shows the JSON representation of an object that describes a person. The object has string fields for first name and last name, contains an object representing the person's address, and contains a list of phone numbers (an array).


{
"firstName": "John",
"lastName": "Smith",
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
"212 732-1234",
"646 123-4567"
]
}



The following Javascript code shows how the client can use an XMLHttpRequest to request an object in JSON format from the server. (The server-side programming is omitted; it has to be set up to respond to requests at url with a JSON-formatted string.)


var the_object;
var http_request = new XMLHttpRequest();
http_request.open( "GET", url, true );
http_request.onreadystatechange = function () {
if ( http_request.readyState == 4 ) {
if ( http_request.status == 200 ) {
the_object = eval( "(" + http_request.responseText + ")" );
} else {
alert( "There was a problem with the URL." );
}
http_request = null;
}
};





More info at http://www.json.org