Cross Document messaging 통신
다른 사이트 페이지끼리 통신 하기


참조 URL
  1. https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage
  2. http://m.mkexdev.net/75
  3. http://jjeong.tistory.com/476
  4. postMessage를 이용한 크로스도메인간 iframe 리사이징
  5. http://jsonobject.tistory.com/53





[그림1] postMessage를 통한 크로스 사이트 통신



 '그림1'에서와 같이 페이지에서 iFrame로 임베이딩된 상태에서는 브라우저의 보안 정책으로 인해 자바스크립트를 통해 페이지간 통신을 할 수 없었다. 하지만 postMessage를 통해서 가능하게 되었다. 지원하는 브라우저는 아래 '그림2'에서와 같이 IE8에서부터 지원이 되므로 거의 대부분의 브라우저에서 지원된다고 보면 될 것이다.



[그림2] postMessage 브라우저 호환표

http://caniuse.com/#feat=x-doc-messaging )


 이제 postMessage의 사용법에 대해서 알아 보자



데이터 송신하기


데이터를 송신하기 위해서는 window 객체의 postMessage 함수를 사용하면 된다


[코드1] 데이터 송신



data: 전달할 메세지, 즉 송신할 데이터를 지정한다

ports: 메세지를 전송할 포트(생략 가능)

targetOrigin: 타켓 도메인,  즉 메세지를 수신받는 도메인을 지정한다 대상이 특정 도메인이 아니라면 * 로 지정한다 




데이터 수신하기


데이터를 수신하는 측에서는 단순히 window 객체의 message 이벤트를 구현하면 된다


[코드2] 데이터 수신



data: 메세지 즉 송신한 데이터이다

origin: 메세지를 보내는 곳의 도메인 정보 크로스 도메인 환경이라면 상대 도메인을 확인하는 것이 보안상 좋다

source: 메세지를 보내는 윈도우 객체 



이제 이 코드를 가지고 아래 예제 코드로 활용법을 보도록 하자.



[코드] 송신쪽 페이지 코드



[코드] 수신쪽 페이지 코드



Syntax

otherWindow.postMessage(message, targetOrigin, [transfer]);



otherWindow

A reference to another window; such a reference may be obtained, for example, using the contentWindow property of an iframe element, the object returned by window.open, or by named or numeric index on window.frames.


message

Data to be sent to the other window.


targetOrigin

Specifies what the origin of otherWindow must be for the event to be dispatched, either as the literal string "*" (indicating no preference) or as a URI. If at the time the event is scheduled to be dispatched the scheme, hostname, or port of otherWindow's document does not match that provided in targetOrigin, the event will not be dispatched; only if all three match will the event be dispatched. This mechanism provides control over where messages are sent; for example, if postMessage were used to transmit a password, it would be absolutely critical that this argument be a URI whose origin is the same as the intended receiver of the message containing the password, to prevent interception of the password by a malicious third party. Always provide a specific targetOrigin, not *, if you know where the other window's document should be located. Failing to provide a specific target discloses the data you send to any interested malicious site.


transfer [Optional]

Is a sequence of Transferable objects that are transferred with the message. The ownership of these objects is given to the destination side and they are no more usable on the sending side.












CSS3 Transition example site


참조 URL
  1. http://www.creativesandbox.com/guidebook
  2. http://2012.beercamp.com/



CSS3의 Transition 기능을 이용해서 만든 사이트다.












CSS Transition를 이용한 버튼 애니메이션 효과


참조 URL
  1. http://html5snippets.com/snippets/59-introduction-to-css3-animations
  2. http://www.the-art-of-web.com/css/css-animation/#.Ufm1yJLxqlg
  3. http://www.creativebloq.com/css3/animation-with-css3-712437
  4. http://lab.tylergaw.com/themanfromhollywood/
  5. http://cssdeck.com/labs/google-doodle-in-css-follow-up
  6. http://www.clicktorelease.com/code/css3dclouds/
  7. http://tympanus.net/Tutorials/AnimatedButtons/index2.html
  8. http://tympanus.net/Tutorials/OriginalHoverEffects/index.html
  9. http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/css3-transitions-and-transforms-from-scratch/
  10. http://2012.beercamp.com/
  11. http://www.creativesandbox.com/guidebook


 HTML5가 나오면서 CSS로 애니메이션을 할 수 있는 방법이 나오게 되었다. 이전에는 Javascript로 구현해야 하였기에 많은 CPU와 복잡한 로직으로 되어야 했지만 CSS의 Taansition을 통해 그나마 쉽게 컨트롤 할 수 있게 되었다. 이와 관련해서 여러가지 예제와 샘플들이 있지만 아래와 같이 버튼에 대해서 효과를 주는 간단한 CSS를 소개해 주고자 한다.



CSS의 Transition을 지원하는 브라우저에서만 확인할 수 있다. 예) 최신 Chrome browser
박스를 마우스 오버 시키면 박스가 빠르게 회전을 하고
마우스 Leave 시키면 반대편으로 빠르게 회전하여 돌아오는 CSS Transition 데모다.
  • A
  • B








위 표현은 아래 코드를 통해서 나타낸다.




[코드] HTML의 Style 선언




[코드] HTML의 Tag 선언



 HTML 5의 CSS3 Transition에 가장 잘 표현한 사이트가 있으니 여기에서 확인해 보고 경이로움을 같이 공유하였으면 합니다.

http://www.clicktorelease.com/code/css3dclouds/



그리고 어린이 도서와 같은 팝업북 같은 느낌의 사이트

http://www.creativesandbox.com/guidebook - 강추






HTML Template


2013.09.24 Update


참조 URL
  1. http://designsbydarren.com/
  2. http://freehtml5templates.com/
  3. https://www.jetstrap.com/ TwitterBootstraper 이용해서 template 제공
  4. http://bootswatch.com/
  5. https://wrapbootstrap.com/  - 유료지만 퀄리티가 높음
  6. http://stylebootstrap.info/
  7. http://builtwithbootstrap.com/
  8. http://www.bootstraptor.com/


 HTML 페이지를 처음부터 설계하고 레이아웃을 잡고, CSS 작업을 하는건 어떤 사람들에게는 중노동이 될 수 있다. 그렇지만 기초 공사가 되어 있는 상태에서 나머지 치장을 조금씩 할 수 있다면 무척 감사할 수 있을 것이다. 지금과 같이 기초 공사가 되어 있는 템플릿을 제공해 주는 사이트가 있어서 소개 하고자 한다. 


 이번에는 JetStrap 사이트에 대해서만 소개하고자 한다. 나머지는 직접 들어가서 확인해 보면 될 것이다. 아래 '그림1'은 JetStrap 사이트의 메인 화면이다. 이 사이트는 TwitterBootStraper을 이용해서 템플릿을 제공해 주고 있으며 '그림2'에서 보는바와 같이 템플릿을 Drag&Drop로 편집하여 다운 받을 수 있도록 하고 있다. 수정된 템플릿을 다운받아 수정 후 배포를 하면 될 것이다.


[그림1] JetStrap 사이트



[그림2] 템플릿 편집 화면



 부디 많은 사람들이 손 쉽게 웹 사이트나 페이지를 만들 수 있었으면 한다. TwitterBootstraper를 이용해 만든 템플릿이라 여러 브라우저에 호환성이 있는 템플릿이다.


 이 밖에도 이와 같이 템플릿을 제공해 주는 사이트가 많이 있으니 자신에게 적당한 곳에서 실험해 보면 될 것이다.

'설치 및 소개' 카테고리의 다른 글

codepen.io - Live HTML dev environment  (0) 2013.05.10
WebSocket - FlashSocket - Cross Browser support  (0) 2013.05.04
[WebMatrix] WebMatrix 3 Preview  (0) 2013.05.01
개발 그룹 사이트 링크  (0) 2012.11.12
WebMatrix 사용하기 #2  (0) 2012.11.09

+ Recent posts