Skip to content

Instantly share code, notes, and snippets.

@getJv
Last active October 11, 2020 05:18
Show Gist options
  • Save getJv/341632f70d1a00db00f58d736b98dac1 to your computer and use it in GitHub Desktop.
Save getJv/341632f70d1a00db00f58d736b98dac1 to your computer and use it in GitHub Desktop.
A sample of using the window postMessage from guest-page
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
<div id="app">
<v-app>
<v-main>
<v-container ref="container" >
<h2>Guest Page</h2>
<v-row justify="center" align="center" >
<v-col cols="12" sm="3" v-for="item in [1,2,3,4]" :key="item" >
<v-card color="green darken-3" :height="200">
<v-card-text class="title text-center white--text">
Item #{{ item }}
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-container>
</v-main>
</v-app>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.js"></script>
<script>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data(){
return {
timer: ''
}
},
mounted(){
this.timer = setInterval(this.iframeHeightNotify,300)
},
beforeDestroy() {
clearInterval(this.timer);
},
methods:{
iframeHeightNotify(){
var msg = {
height: this.$refs.container.scrollHeight
}
window.parent.postMessage(msg,'*')
}
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment