- A JSON object is an unordered set of name/value pairs
- A JSON object begins with { (left brace) and ends with } (right brace)
- Each name is followed by : (colon) and the name/value pairs are separated by , (comma)
Tag Archives: Javascript
Why Use JSON over XML
- Lighter and faster than XML as on-the-wire data format
- JSON objects are typed while XML data is typeless
- Native data form for JavaScript code
JSON
Print a Web Page Using JavaScript
<a href=”javascript:window.print()”>Print</a>
Check javascript is enabled in the browser + php
<noscript>Please enable Javascript</noscript>
javascript load a url in new tab
javascript:window.open(‘www.example.oom’,’_blank’)
How to block right click on a page
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”)
Load page content based on menu using simple javascript
Paste the below given code in page and load that so as to get a better idea of how it works .
function NextPage($pageID){
for($i=1;$i
<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>
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).
</td>
</tr>
</table>
What is Ajax?
This is not a new language but a new technique using the existing standards like HTML,Javascript.
Using Ajax,we can fetch the data from the server without loading the whole page and do the DB operations as well .
Here is an example
function displaySize(sVal){
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert (“Your browser does not support AJAX!”);
return;
}
var url=”ajax-page.php?”;
url=url+”&sVal=”+sVal;
url=url+”&sid=”+Math.random();
//alert(url);
xmlHttp.onreadystatechange=stateChangedSize;
xmlHttp.open(“GET”,url,true);
xmlHttp.send(null);
}
function stateChangedSize(){
if (xmlHttp.readyState==4)
document.getElementById(“dimension”).innerHTML=xmlHttp.responseText;
}
function GetXmlHttpObject(){
var xmlHttp=null;
try {// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) {// Internet Explorer
try {
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e){
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
}
return xmlHttp;
}
<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>
<?php
switch($_REQUEST[‘sVal’]){
case “header”:echo “780 x 100”;break;
case “footer”:echo “180 x 300”;break;
case “sidebar”:echo “180 x 200”;break;
default:echo “880 x 200”;break;
}
?>
Get current site URL – Javascript
alert( document.URL );