Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Component on new window

<window-portal>
  I appear in a new window!
</window-portal>
Comment

Component on new window

<template>
  <div v-if="open">
    <slot />
  </div>
</template>

<script>
export default {
  name: 'window-portal',
  props: {
    open: {
      type: Boolean,
      default: false,
    }
  },
  data() {
    return {
      windowRef: null,
    }
  },
  watch: {
    open(newOpen) {
      if(newOpen) {
        this.openPortal();
      } else {
        this.closePortal();
      }
    }
  },
  methods: {
    openPortal() {
      this.windowRef = window.open("", "", "width=600,height=400,left=200,top=200");
      this.windowRef.addEventListener('beforeunload', this.closePortal);
      // magic!
      this.windowRef.document.body.appendChild(this.$el);
    },
    closePortal() {
      if(this.windowRef) {
        this.windowRef.close();
        this.windowRef = null;
        this.$emit('close');
      }
    }
  },
  mounted() {
    if(this.open) {
      this.openPortal();
    }
  },
  beforeDestroy() {
    if (this.windowRef) {
      this.closePortal();
    }
  }
}
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: add types to React$Context in flow 
Javascript :: microseconds to current time js code 
Javascript :: custu, loading next js 
Javascript :: react computed hook 
Javascript :: jquery ui music player 
Javascript :: sequilize join two tables and find 
Javascript :: koa get post body 
Javascript :: acceder a variable css desde js 
Javascript :: make a count button i js 
Javascript :: my code agly because alot of if and else dev community 
Javascript :: Using a fallback if module loading fails 
Javascript :: Solana SPL Token JavaScript library mint function 
Javascript :: binary conversion recursion in javascript 
Javascript :: typeorm caching queries time limit 
Javascript :: joi validation error message in path parameter value array to string 
Javascript :: vuejs check word is availble in the string or not 
Javascript :: change style selected text js 
Javascript :: observables loop in template angular 8 
Javascript :: Promisify with ajax call 
Javascript :: used as a function, Number() will convert another value 
Javascript :: Async restricted or not 
Javascript :: javascript span containing text 
Javascript :: what is the maximum x value of a window for mouse listener 
Javascript :: loop through async javascript -5 
Javascript :: Insert tag in XML text for mixed words 
Javascript :: discord.js play song 
Javascript :: e.stopPropagation() is not working as expected 
Javascript :: Unhandled Navigation Error: angular dist build 
Javascript :: diable input javascript 
Javascript :: hide react from netlify 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =