JavaScript

Create JSON Object in JavaScript

1
2
3
4
5
6
7
8
9
10
11
12
13
var json = {};
var singleObj = [];
var obj = new Object; //Remember to declare an object so you can add key to it
obj.key1 = "value1";
obj.key2 = "value2";
singleObj.push(obj);
json["singleObj"] = singleObj;
var jsonString = JSON.stringify(json); //Change JSON Object to String
window.console.log(jsonString);
//{"singleObj":[{"key1":"value1","key2":"value2"}]}

Print Out Iframe using Javascript

You can print out a page by putting it to an iframe, then print out it: \

1
2
3
4
5
6
7
8
9
//Create iframe element (skip this if you already had one)
var iframe = document.createElement("iframe");
iframe.src = "Link_To_Your_Page";
iframe.id = "printOut";
iframe.style = "display:hidden"; //You can skip this if you want to show iframe on your page
document.body.appendChile("iframe");
document.getElementById("printOut").focus();
document.getElementById("printOut"),contentWindow.print(); //print out iframe