AI ์ด์ „์‹œ๋Œ€ (↓์„๊ธฐ์‹œ๋Œ€ IT)/02. Javascript Html

HTML5 jQuery ๊ฐ•์ขŒ #2 (20120328)

๐Ÿ“ฆ DonzBox 2012. 3. 27. 10:42


Cookie -> WEB Storage (client side data ์ €์žฅ (key-value)) ์ฟ ํ‚ค์˜ ๋Œ€์ฒด๋Š” ์•„๋‹Œ ์ƒˆ๋กœ์šด ๊ธฐ์ˆ 


HTTP์˜ ํŠน์ง•(stateless)

 - ํด๋ผ์ด์–ธํŠธ์˜ ์ปค๋„ฅ์…˜์„ ์„œ๋ฒ„์— ํ•œ๋ฒˆ ์š”์ฒญ์„ ํ•˜๋ฉด ์‘๋‹ต์„ ์ฃผ๊ณ  ๋Š์–ด๋ฒ„๋ฆฐ๋‹ค

 - ํด๋ผ์ด์–ธํŠธ๋Š” ์„œ๋ฒ„์— ์ ‘์†์‹œ ๋งˆ๋‹ค ์„œ๋ฒ„๋Š” ์ƒˆ๋กœ์šด ์ปค๋„ฅ์…˜์œผ๋กœ ์ธ์‹ํ•˜๋ฏ€๋กœ ๋™์ผ ํด๋ผ์ด์–ธํŠธ์—์„œ ์ ‘์†ํ•˜๋”๋ผ๋„ ๊ตฌ๋ถ„ํ•  ์ˆ˜ ์—†๋‹ค.

   - ๋Œ€์•ˆ : session(์„œ๋ฒ„side์— ํด๋ผ์ด์–ธํŠธ์ •๋ณด ์ €์žฅ)

               cookie(ํด๋ผ์ด์–ธํŠธ์˜ ์ƒํƒœ์ •๋ณด ์ €์žฅ)์˜ ํ™œ์šฉ

                - request ์— cookie ๋ฐ์ดํ„ฐ๋ฅผ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์•Œ์•„์„œ ํ•ด๋‹น ๋„๋ฉ”์ธ์„ responseํ• ๋•Œ head์— ๋ถ™์—ฌ ์„œ๋ฒ„๋กœ ๋„˜๊ฒจ์ฃผ๋Š” ํ˜•ํƒœ

                  (์„œ๋ฒ„๊ฐ€ ํ•„์š”์—†๋Š” ์ฟ ํ‚ค์ •๋ณด๋ฅผ ๋ชจ๋‘ ๋„˜๊ฒจ์ฃผ๋Š” ํ˜•ํƒœ์ž„)


----------------------------------------------------------------

 WEB Storage ๊ตฌํ˜„

----------------------------------------------------------------

01. ์‹ค์žฅ

<!DOCTYPE html>

<html>

<head>

<meta charset=EUC-KR">

<title>Insert title here</title>

<script>

window.onload = function(){

var removeBtn = document.getElementById("removeBtn");

var addBtn    = document.getElementById("addBtn");

removeBtn.addEventListener("click", remove); //removeBtn์— click์ด๋ฒคํŠธ ๋ฐœ์ƒ์‹œ removeํ•จ์ˆ˜ ํ˜ธ์ถœ

addBtn.addEventListener("click", add);       //addBtn์— click์ด๋ฒคํŠธ ๋ฐœ์ƒ์‹œ addํ•จ์ˆ˜ ํ˜ธ์ถœ

load();

}

// SelectBox ๊ฐฑ์‹ 

function load() {

var list = document.getElementById("list");

list.innerHTML = "";

for (var i=0 ; i<localStorage.length ; i++) {

var key = localStorage.key(i);

list.options[list.options.length] = new Option(localStorage[key], key);

}

}

function remove() {

var list = document.getElementById("list");

if (list.selectedIndex < 0) return; // ์•„๋ฌด๊ฒƒ๋„ ์„ ํƒ๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด

var selected = list.options[list.selectedIndex].value;

localStorage.removeItem(selected);

load();

}

function add() {

var key   = document.getElementById("key").value;

var value = document.getElementById("value").value;

localStorage[key] = value;

load();

}

</script>

</head>

<body>

<h1>Web Storage Test</h1>

<p>

<select id="list" style="width:100px"></select>

<button id="removeBtn">remove</button>

</p>

<p>

key : <input type="text" id="key"> - value <input type="text" id="value">

<button id="addBtn">add</button>

</p>

</body>

</html>


02. ์‹คํ–‰




 (F12๋ฅผ ๋ˆ„๋ฅด๋ฉด ๋‚˜์˜ด)




----------------------------------------------------------------

 WEB SQL Database ๊ตฌํ˜„ (W3C ์—์„œ Drop ํ•œ ๋ฉ”์†Œ๋“œ์ž„)

----------------------------------------------------------------

Drop๋œ ์ด์œ 

  00. W3C๋Š” ๋ธŒ๋ผ์šฐ์ ธ ๋ฐด๋”๋“ค์—๊ฒŒ ๊ฐ•์ œ๋กœ SQLite๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋Š” ๊ถŒํ•œ์ด ์—†์Œ

  01. SQL์„ ๋ชจ๋ฅด๋Š” ์‚ฌ๋žŒ๋“ค์œ„ํ•ด

  02. ํŠน์ • ๋ธŒ๋ผ์šฐ์ ธ ๋ฐด๋“œ๊ฐ€ ๋…์žDB๋ฅผ ์ž„๋ฒ ๋””๋“œ ์‹œ์ผฐ์„๋•Œ SQL๋ฌธ์ด ํ‹€๋ ค์งˆ ์ˆ˜ ์žˆ์Œ



 SQLite(RDBMS) - OpenSource, ์•ˆ์ •์„ฑ, ๊ฒฝ๋Ÿ‰, ์ด์šฉํŽธ์˜์„ฑ

  - ๋ธŒ๋ผ์šฐ์ €์— ๋‚ด์žฅ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ DB Connectionํ•„์š”์—†์Œ, ๋‹จ์œ„์ฒ˜๋ฆฌ, ํŠธ๋ Œ์žญ์…˜์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ


01. ์‹ค์žฅ


<!DOCTYPE html>

<html>

<head>

<meta charset=EUC-KR">

<title>Insert title here</title>

<script>

// DB ์ดˆ๊ธฐํ™”

var db = openDatabase("dbtest", "", "DB TEST", "1024*1024");

// Table ์ค€๋น„

db.transaction(function(tx) {

tx.executeSql("create table if not exists m_tb ("

                   + "_id integer primary key autoincrement,"

                   + "name not null,"

                   + "phone not null)");

});

window.onload = function(){

var removeBtn = document.getElementById("removeBtn");

var addBtn    = document.getElementById("addBtn");

removeBtn.addEventListener("click", remove); //removeBtn์— click์ด๋ฒคํŠธ ๋ฐœ์ƒ์‹œ removeํ•จ์ˆ˜ ํ˜ธ์ถœ

addBtn.addEventListener("click", add);       //addBtn์— click์ด๋ฒคํŠธ ๋ฐœ์ƒ์‹œ addํ•จ์ˆ˜ ํ˜ธ์ถœ

load();

}

// SelectBox ๊ฐฑ์‹ 

function load() {

db.transaction(function(tx) {

tx.executeSql("select * from m_tb", [],                    // ?์— ๋„ฃ์„๊ฐ’

            function(tx, rs) {                           // ์„ฑ๊ณต์‹œ

var list = document.getElementById("list");

list.innerHTML = "";

var rows = rs.rows;

for (var i=0 ; rows.length ; i++) {

var row = rows.item(i);

list.options[list.options.length] = new Option(row.name, row._id);

}

});

});

var list = document.getElementById("list");

list.innerHTML = "";

for (var i=0 ; i<localStorage.length ; i++) {

var key = localStorage.key(i);

list.options[list.options.length] = new Option(localStorage[key], key);

}

}

    function remove() {

        var list = document.getElementById("list");

        if (list.selectedIndex < 0) return; // ์•„๋ฌด๊ฒƒ๋„ ์„ ํƒ๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด

        var selected = list.options[list.selectedIndex].value;

        db.transaction(function(tx) {

            tx.executeSql("delete from m_tb where _id=?", [selected], // ?์— ๋„ฃ์„๊ฐ’

            function() {                                // ์„ฑ๊ณต์‹œ

load();

}); 

        });

    }

    function add() {

        var name  = document.getElementById("name").value;

        var phone = document.getElementById("phone").value;

        db.transaction(function(tx) {

            tx.executeSql("insert into m_tb (name,phone) values(?,?)", [name, phone],

                         function() {                                // ์„ฑ๊ณต์‹œ

                            load();

                         });

        });

    }

</script>

</head>

<body>

<h1>Web SQL Database Test</h1>

<p>

<select id="list" style="width:100px"></select>

<button id="removeBtn">remove</button>

</p>

<p>

name : <input type="text" id="name"> - phone <input type="text" id="phone">

<button id="addBtn">add</button>

</p>

</body>

</html>


02. ๊ฒฐ๊ณผ (F12๋ฅผ ๋ˆ„๋ฅด๋ฉด ๋‚˜์˜ด)





--------------------------------
--------------------------------

 Indexed DB (SQLite์˜ ๋Œ€์•ˆ) - ์ง€์›๋˜๋Š” ๋ธŒ๋ผ์šฐ์ ธ๊ฐ€ ํ˜„์‹œ์  ๊ทน์†Œ

----------------------------------------------------------------

๊ฐ์ฒด๋ฅผ ๊ตฌ์กฐํ™”์‹œ์ผœ ๋‚ด๋ถ€์ ์œผ๋กœ๋Š” ๋ฐด๋”๊ฐ€ ์–ด๋– ํ•œ ๋ฐฉ์‹์œผ๋กœ๋“ (์˜ˆ:SQLite์ด์šฉ) ๋ธŒ๋ผ์šฐ์ ธ์— ์ €์žฅ ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•˜๋Š” ๋ฐฉ์‹



-------------------------------------------------------------------------------------------------



----------------------------------------------------------------

Communucation API

----------------------------------------------------------------


๋™๊ธฐํ†ต์‹  - ํด๋ผ์ด์–ธํŠธ์—์„œ ์„œ๋ฒ„๋กœ ๋ฐ์ดํ„ฐ ์š”์ฒญ์‹œ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋งŒ๋“ค์–ด์ง„ request ๋ฐ์ดํ„ฐ๋ฅผ ์„œ๋ฒ„์—์„œ ๋ฐ›์•„, ์„œ๋ฒ„๋Š” response          

                ๋ฐ์ดํ„ฐ๋ฅผ ๋งŒ๋“ค์–ด ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „๋‹ฌํ•ด ์ค€๋‹ค (ํด๋ผ์ด์–ธํŠธ๋Š” ์„œ๋ฒ„์˜ ์‘๋‹ต์„ ๋ฐ›์„ ๋•Œ ๊นŒ์ง€, ์–ด๋– ํ•œ ๋™์ž‘๋„ ํ•  ์ˆ˜ ์—†๋‹ค)

                ๋น„๋™๊ธฐํ†ต์‹  - AJAX


stateless - client ์ ‘์†์ƒํƒœ์œ ์ง€๋ฅผ ์œ„ํ•ด session, cookie, web storage

                realtime dataํ†ต์‹  ๋ถˆ๊ฐ€ : C/S ์ปค๋„ฅ์…˜์ด ๋Š์–ด์ง„ ์ƒํƒœ๋กœ, ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ๋Š” ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•  ์ˆ˜ ์—†๋‹ค.

                ๋Œ€์•ˆ : polling (ํด๋ผ์ด์–ธํŠธ์—์„œ ์ผ์ •์‹œ๊ฐ„ ์„œ๋ฒ„์— ์—ฐ๊ฒฐ์‹œ๋„) - ๋„คํŠธ์› ํŠธ๋ ˆํ”ฝ ์ดˆ๋ž˜

                         comet : ํด๋ผ์ด์–ธํŠธ์—์„œ ์š”์ฒญ์„ ํ•˜๋ฉด ์„œ๋ฒ„๋Š” ์‘๋‹ต์„ ํ•˜์ง€ ์•Š๊ณ  ์žˆ๋‹ค๊ฐ€ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒ๋˜๋ฉด ์„œ๋ฒ„์—์„œ ๊ทธ๋•Œ์„œ์•ผ

                                    ์‘๋‹ต์„ ํ•จ - ํด๋ผ์ด์–ธํŠธ๋Š” ๋Œ€๊ธฐํ™”๋ฉด์ด์ง€๋งŒ innerFrame=0 ๋ถ€๋ถ„์œผ๋กœ ๋„˜๊ธฐ๊ณ  ๋ถ€๋ชจ์ฐฝ์œผ๋กœ ๋„˜๊น€

                 HTML5 ๋Œ€์•ˆ : web socket (web socket ์ „์šฉ ์„œ๋ฒ„๊ฐ€ ํ•„์š”ํ•จ), server sent event (์ฃผ๊ธฐ์ ์ธ C/S ํ†ต์‹ )


SameOrigin Policy - ์„œ๋กœ ๋‹ค๋ฅธ ์„œ๋ฒ„์—์„œ ํ•˜๋‚˜์˜ ํด๋ผ์ด์–ธํŠธ์™€ ์ ‘์†๋˜์—ˆ์„๋•Œ ํด๋ผ์ด์–ธํŠธ์˜ ์ •๋ณด๋ฅผ ๊ณต์œ ํ•  ์ˆ˜ ์—†๋‹ค

                                 (์„œ๋ธŒ ๋„๋ฉ”์ธ์˜ ๊ฒฝ์šฐ๋„ ๋ฉ”์ธ๋„๋ฉ”์ธ๊ณผ ๋‹ค๋ฅธ ๋„๋ฉ”์ธ์œผ๋กœ ์ทจ๊ธ‰)

                ๋Œ€์•ˆ : Cross Document Message


Web Worker - JavaScript Thread Program (node.js, ์„œ๋ฒ„:๊ตฌ๊ธ€์˜ V8์—”์ง„) - ๋ชจ๋ฐ”์ผ์—์„œ ์•ˆ๋จ



----------------------------------------------------------------

 Crocess Document

----------------------------------------------------------------

์ƒ์ดํ•œ ๋„๋ฉ”์ธ (์„œ๋กœ๋‹ค๋ฅธ ๋„๋ฉ”์ธ์„ ๊ฐ€์ง„ document ๊ฐ„์˜ ๊ฐ์ฒด ์ „์†ก์„ ์œ„ํ•œ ๊ธฐ์ˆ )


01. ํ™˜๊ฒฝ์„ค์ •



02. Dynamic Web Project ๋กœ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ



03. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ๊ณ„์†



04. ์•„๋ž˜์™€ ๊ฐ™์ด ์ฝ”๋“œ ์‹ค์žฅ (์ผ๋‹จ inner.html ๋กœ twitter ์˜ ๊ฒ€์ƒ‰ ๋‚ด์šฉ ๊ฐ€์ ธ์˜ค๊ธฐ ์†Œ์Šค ์งœ๊ธฐ)


<!DOCTYPE html>

<html>

<head>

<meta charset=EUC-KR">

<title>Insert title here</title>

<script>

// dom node ๊ตฌ์กฐ ์ ‘๊ทผ์‹œ ํŽธํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ jquery ์Šคํƒ€์ผ์˜ ํ•จ์ˆ˜

function $(id) {

return document.getElementById(id);

}

window.onload = function() {

search();

}

function search() {

$("results").innerHTML = "";

// ๊ฒ€์ƒ‰๋ฌธ์ž์—ด

var keyword = "kkang";

// callback : ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ process๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ๊ฐœ๋ฐœ์ž ํ•จ์ˆ˜

var query   = "http://search.twitter.com/search.json?callback=process"

                    + "&q=";

query += encodeURI(keyword);

// ์กด์žฌํ•˜์ง€ ์•Š๋Š” script tag๋ฅผ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค

var script = document.createElement("script");

script.src = query;

// ๋งŒ๋“ค์–ด์ง„ tag๋ฅผ ํ—ค๋“œํ…Œ๊ทธ์˜ ์ž์‹๋…ธ๋“œ์— ๋ถ™์ž„, ๋ฐ”๋€ head ์ •๋ณด์— ์˜ํ•ด ํŽ˜์ด์ง€๊ฐ€ ์—ด๋ฆผ

document.getElementsByTagName("head")[0].appendChild(script);

}

// twitter ๊ฒ€์ƒ‰๊ฒฐ๊ณผ๋ฅผ callback ์œผ๋กœ๋กœ ์ง€์ •ํ•œ process ํŽ‘์…˜์œผ๋กœ  ํ•ธ๋“ค๋ง

function process(response) {

var datas = response.results;

// map : ์ง‘ํ•ฉ๊ฐ์ฒด์˜ ๊ฐฏ์ˆ˜๋งŒํผ ์ง€์ •๋œ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœ(ํ•˜๋‚˜ํ•˜๋‚˜ ๋„˜๊น€)

var rows  = datas.map(function(data) {

// ํ•œ ๊ฑด์˜ ๋ฐ์ดํ„ฐ๋กœ ํ™”๋ฉด์— ์ฐ์–ด์ฃผ๊ธฐ ์œ„ํ•œ html ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ํ•จ์ˆ˜ ํ˜ธ์ถœ

return createResult(data.profile_image_url, data.text);

});

// ํ™”๋ฉด ์ถœ๋ ฅ

rows.forEach(function(row) {

$("results").appendChild(row);

});

}

// ๋„˜์–ด์˜จ ๋ฐ์ดํ„ฐ๋กœ ํ™”๋ฉด์— ์ฐ์„ html ๊ตฌ์กฐ๋ฅผ ์™„์„ฑํ•˜๋Š” ํ•จ์ˆ˜

function createResult(src, title) {

var p    = document.createElement("p");

var icon = document.createElement("img");

icon.src = src;

icon.setAttribute("width" , 48);

icon.setAttribute("height", 48);

// p ํ…Œ๊ทธ ์†์— img ํ…Œ๊ทธ๋ฅผ ๋„ฃ๊ณ  ๋ฌธ์ž์—ด๋กœ ๋งŒ๋“ฌ

p.appendChild(icon);

p.appendChild(document.createTextNode(title));

return p;

}

</script>

</head>

<body>

    <div id="results"></div>

</body>

</html>


05. ๊ฒ€์ƒ‰๊ฒฐ๊ณผ ํ™•์ธ (์„ค์ •ํ•œ ๋„๋ฉ”์ธ์œผ๋กœ ๊ฒ€์ƒ‰๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•œ๋‹ค)




๋ณธ๊ฒฉ์ ์ธ crocess document ํ…Œ์ŠคํŠธ


inner.html

<!DOCTYPE html>

<html>

<head>

<meta charset=EUC-KR">

<title>Insert title here</title>

<script>

// dom node ๊ตฌ์กฐ ์ ‘๊ทผ์‹œ ํŽธํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ jquery ์Šคํƒ€์ผ์˜ ํ•จ์ˆ˜

function $(id) {

return document.getElementById(id);

}

// outter์—์„œ ๋„˜์–ด์˜ค๋Š” MessageEvent ์‹œ ํ˜ธ์ถœ๋  ํ•จ์ˆ˜

function messageHandler(e) {

if (e.origin == "http://localhost:8080") {

search(e.data);

}

}

window.onload = function() {

//search();

// message ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค๋ฉด messageHandlerํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋ผ

window.addEventListener("message", messageHandler);

}

function search(keyword) {

$("results").innerHTML = "";

// ๊ฒ€์ƒ‰๋ฌธ์ž์—ด

//var keyword = "kkang";

// callback : ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ process๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ๊ฐœ๋ฐœ์ž ํ•จ์ˆ˜

var query   = "http://search.twitter.com/search.json?callback=process"

                    + "&q=";

query += encodeURI(keyword);

// ์กด์žฌํ•˜์ง€ ์•Š๋Š” script tag๋ฅผ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•˜๊ฒ ๋‹ค

var script = document.createElement("script");

script.src = query;

// ๋งŒ๋“ค์–ด์ง„ tag๋ฅผ ํ—ค๋“œํ…Œ๊ทธ์˜ ์ž์‹๋…ธ๋“œ์— ๋ถ™์ž„, ๋ฐ”๋€ head ์ •๋ณด์— ์˜ํ•ด ํŽ˜์ด์ง€๊ฐ€ ์—ด๋ฆผ

document.getElementsByTagName("head")[0].appendChild(script);

}

// twitter ๊ฒ€์ƒ‰๊ฒฐ๊ณผ๋ฅผ callback ์œผ๋กœ๋กœ ์ง€์ •ํ•œ process ํŽ‘์…˜์œผ๋กœ  ํ•ธ๋“ค๋ง

function process(response) {

var datas = response.results;

// map : ์ง‘ํ•ฉ๊ฐ์ฒด์˜ ๊ฐฏ์ˆ˜๋งŒํผ ์ง€์ •๋œ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœ(ํ•˜๋‚˜ํ•˜๋‚˜ ๋„˜๊น€)

var rows  = datas.map(function(data) {

// ํ•œ ๊ฑด์˜ ๋ฐ์ดํ„ฐ๋กœ ํ™”๋ฉด์— ์ฐ์–ด์ฃผ๊ธฐ ์œ„ํ•œ html ๊ตฌ์กฐ๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ํ•จ์ˆ˜ ํ˜ธ์ถœ

return createResult(data.profile_image_url, data.text);

});

// ํ™”๋ฉด ์ถœ๋ ฅ

rows.forEach(function(row) {

$("results").appendChild(row);

});

}

// ๋„˜์–ด์˜จ ๋ฐ์ดํ„ฐ๋กœ ํ™”๋ฉด์— ์ฐ์„ html ๊ตฌ์กฐ๋ฅผ ์™„์„ฑํ•˜๋Š” ํ•จ์ˆ˜

function createResult(src, title) {

var p    = document.createElement("p");

var icon = document.createElement("img");

icon.src = src;

icon.setAttribute("width" , 48);

icon.setAttribute("height", 48);

// p ํ…Œ๊ทธ ์†์— img ํ…Œ๊ทธ๋ฅผ ๋„ฃ๊ณ  ๋ฌธ์ž์—ด๋กœ ๋งŒ๋“ฌ

p.appendChild(icon);

p.appendChild(document.createTextNode(title));

return p;

}

</script>

</head>

<body>

    <div id="results"></div>

</body>

</html>


outter.html

<!DOCTYPE html>

<html>

<head>

<meta charset=EUC-KR">

<title>Insert title here</title>

<style>

iframe {

width : 800px;

height: 400px;

}

</style>

<script>

window.onload = function() {

var searchBtn = document.getElementById("searchBtn");

searchBtn.addEventListener("click", search);

}

function search() {

var searchTxt = document.getElementById("keyword").value;

// Cross Document ๋กœ ๋ฐ์ดํ„ฐ ์ „์†ก

document.getElementById("inner").contentWindow.postMessage(searchTxt, "http://www.test.com:8080");

}

</script>

</head>

<body>

<p>

    keywork : <input type="text" id="keyword" width="500">

<button id="searchBtn">search</button>

</p>

<p>

<iframe id="inner" src="http://www.test.com:8080/Ch4-Communication/inner.html"></iframe>

</p>

</body>

</html>


๊ฒฐ๊ณผ : outter.html (http://localhost:8080/Ch4-Communication/outter.html) ์„ ์‹คํ–‰์‹œ์ผœ 

         inner.html (http://www.test.com:8080/Ch4-Communication/inner.html) ์—์„œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•œ๋‹ค


         ๋กœ์ปฌ ์ฃผ์†Œ๋ฅผ ํ†ตํ•˜์—ฌ www.test.com:8080 ์—์„œ ์‹คํ–‰๋œ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.

         document.getElementById("inner").contentWindow.postMessage(searchTxt, "http://www.test.com:8080");

         ๋กœ ์ธํ•˜์—ฌ ๊ฐ€๋Šฅ





--------------------------------
-----------------------------------------------------------------



----------------------------------------------------------------

CANVAS

----------------------------------------------------------------


canvas : pixel

SVG     : vector (http://svg-wow.org/)



----------------------------------------------------------------

VIDEO Control (์•ˆ๋“œ๋กœ์ด๋“œ์™€ ํƒ€๋ธŒ๋ผ์šฐ์ €์˜ ๋™์ž‘์ด ์ƒ์ดํ•˜๋ฏ€๋กœ ์ฃผ์˜ํ• ๊ฒƒ)

----------------------------------------------------------------


01. ํ”„๋กœ์ ํŠธ๋ฅผ Dynamic Web Project ๋กœ ์ƒ์„ฑ ํ•˜์—ฌ video.html ํŒŒ์ผ ์‹ค์žฅ


<!DOCTYPE html>

<html>

<head>

<meta charset=EUC-KR">

<title>Insert title here</title>

<script>

var video;

window.onload = function() {

var device;

video = document.getElementById("video");

//*******************************************

// user agent ๊ฐ’์œผ๋กœ ํ˜„ ๋””๋ฐ”์ด์Šค์˜ ์ •๋ณด๋ฅผ ๋ฝ‘์•„๋ƒ„

//*******************************************

var agent = navigator.userAgent;

if (agent.toUpperCase().indexOf("IPHONE") > -1) {

device = "iPhone";

} else if (agent.toUpperCase().indexOf("ANDROID") > -1) {

device = "Android";

// Android4.0 ICS ํฐ(2012.03์›” ํ˜„์žฌ ์ตœ์‹ ๋ฒ„์ „)์—์„œ์˜ ๋ธŒ๋ผ์šฐ์ €๋Š”

// html5 video play ๋ฅผ ํ…Œ์Šคํฌํƒ‘ ๋ธŒ๋ผ์šฐ์ €์™€ ๋™์ผ ๋ฐฉ๋ฒ•์œผ๋กœ ์ฒ˜๋ฆฌ

if (agent.toUpperCase().indexOf("ANDROID 4.0") > -1) {

device = "Android4.0";

}

} else {

device = "unKnown";

}

//*********************************************************

// ์ค‘์š” : ์•ˆ๋“œ๋กœ์ด๋“œ์šฉ์€ ์ปจํŠธ๋กค๋ฐ”๋ฅผ ๋นผ์•ผํ•จ, ์†Œ์Šค์˜ ํƒ€์ž…์„ ๋นผ์•ผํ•จ

//*********************************************************

if (device == "Android") {

var videodiv = document.getElementById("myvideo");

videodiv.innerHTML = "<video id='video' poster='bbb_poster-360x240.jpg' width='360' height='240'>"

                               + "    <source src='BigBuck.m4v'        />"

                               + "    <source src='BigBuck.webm'       />"

                               + "    <source src='BigBuck.theora.ogv' />"

  + "</video>"

  + "<p><input type='button' onClick='play()' value='play' /></p>";

}

}

    

    function play(){

        video.play();

    }

</script>

</head>

<body>

<!-- -----------------------------------------------------

          ๋ฐ์Šคํฌํƒ‘ ๋ธŒ๋ผ์šฐ์ €๋‚˜ iPhone ์—์„œ๋А ์•„๋ž˜์™€ ๊ฐ™์ด ์ •์ƒ play๋จ

์•ˆ๋“œ๋กœ์ด๋“œ์˜ ๊ฒฝ์šฐ๋Š” source type์— ๋ช…์‹œ๋˜์–ด ์žˆ์œผ๋ฉด ์•ˆ๋˜๊ณ 

๋ฐ˜๋“œ์‹œ javascript์—์„œ play ๋ช…๋ น์„ ๋‚ด๋ ค์•ผ ํ•จ

------------------------------------------------------ -->

    <div id="myvideo">

        <video id="video" poster="bbb_poster-360x240.jpg" width="360" height="240" controls>

    <source src="BigBuck.m4v"        type="video/mp4" />

            <source src="BigBuck.webm"       type="video/webm" />

            <source src="BigBuck.theora.ogv" type="video/ogg" />

    </video>

    </div>

</body>

</html>



02. ํ™•์ธ