From 301d08fb5bfd5b716ab851ce75b3cdcb833e0203 Mon Sep 17 00:00:00 2001 From: xieyu33333 Date: Mon, 15 Aug 2016 17:42:10 +0800 Subject: [PATCH] =?UTF-8?q?get-start=E6=B7=BB=E5=8A=A0postmessage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demos/doc.html | 36 ++++++++++++++++++++---------------- demos/get-start.html | 1 + demos/js/js-code.js | 28 +++++++++++++++++----------- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/demos/doc.html b/demos/doc.html index cc2c0a7..fe1adfb 100644 --- a/demos/doc.html +++ b/demos/doc.html @@ -126,27 +126,31 @@
third part
\ No newline at end of file diff --git a/demos/js/js-code.js b/demos/js/js-code.js index 7271146..2cb9e47 100644 --- a/demos/js/js-code.js +++ b/demos/js/js-code.js @@ -1,17 +1,23 @@ (function() { var demoArea = document.getElementById('demo-script'); - var sourceCodeArea = document.createElement('pre'); - sourceCodeArea.innerHTML = '' + demoArea.innerHTML + '<\/code>'; - if (document.querySelector('.container')) { - document.querySelector('.container').appendChild(sourceCodeArea) - } - else { - document.body.appendChild(sourceCodeArea); + if (demoArea) { + var sourceCodeArea = document.createElement('pre'); + + sourceCodeArea.innerHTML = '' + demoArea.innerHTML + '<\/code>'; + if (document.querySelector('.container')) { + document.querySelector('.container').appendChild(sourceCodeArea) + } + else { + document.body.appendChild(sourceCodeArea); + } } - setTimeout(function() { - var height = parseInt(window.getComputedStyle(document.body).height) + 40; - window.parent.postMessage(height, '*'); - }, 100); + if (window.postMessage) { + setTimeout(function() { + var height = parseInt(window.getComputedStyle(document.body).height) + 40; + console.log(height); + window.parent.postMessage(height, '*'); + }, 100); + } })(); \ No newline at end of file