link0 link1 link2 link3 link4 link5 link6 link7 link8 link9 link10 link11 link12 link13 link14 link15 link16 link17 link18 link19 link20 link21 link22 link23 link24 link25 link26 link27 link28 link29 link30 link31 link32 link33 link34 link35 link36 link37 link38 link39 link40 link41 link42 link43 link44 link45 link46 link47 link48 link49 link50 link51 link52 link53 link54 link55 link56 link57 link58 link59 link60 link61 link62 link63 link64 link65 link66 link67 link68 link69 link70 link71 link72 link73 link74 link75 link76 link77 link78 link79 link80 link81 link82 link83 link84 link85 link86 link87 link88 link89 link90 link91 link92 link93 link94 link95 link96 link97 link98 link99 link100 link101 link102 link103 link104 link105 link106 link107 link108 link109 link110 link111 link112 link113 link114 link115 link116 link117 link118 link119 link120 link121 link122 link123 link124 link125 link126 link127 link128 link129 link130 link131 link132 link133 link134 link135 link136

[Vue.js] Automatically redirect to another page when link is entered in input box

when creating a simple web page that will allow the user to paste a web url link into an input box. Once they have pasted it in then the page will automatically send them to that specific page.

I don’t need a button, just a way for them to paste and then the page loads the url they have pasted.

<template>
<div class=”importEvent”>
<img class=”imageSize” src=”~/assets/Missing Icons/facebook.svg” alt=”Facebook”>
<InputComponent placeholder=”Paste the facebook event here” v-model=”facebookPaste” class=”inputFacebook”></InputComponent>

<div class=”manualOption”>
or <nuxt-link to=”/create-event” class=”manualLink”>create manually</nuxt-link>
</div>
</div>
</template>

If someone can please help, it would be much appreciated.

Many thanks.

Solution :

I think the questions a litil bit awkward well you can set internal and check regularly value of input box when input box get some value redirect to another page

var input_text=””;
var time=setInterval(function(){
input_text=document.getElementsByTagName(“InputComponent”)[0].getAttribute(“value”);
if(input_text.length>0)
{
//redirect code goes here
clearInterval(time);
},500);

here i assume that the element index is 0;
it can be done the keybord eventListner also but there might be some problem if input gose with the help of mouse.

Solution 2:

I don’t know what is the InputComponent, but if use <input> you can try this code:

<template>
<div class=”importEvent”>
<img class=”imageSize” src=”~/assets/Missing Icons/facebook.svg” alt=”Facebook”>
<input type=”text” placeholder=”Paste the facebook event here” class=”inputFacebook” @paste=”pasteLink($event)”/>

<div class=”manualOption”>
or <nuxt-link to=”/create-event” class=”manualLink”>create manually</nuxt-link>
</div>
</div>
</template>
<script>
export default {
methods: {
pasteLink: function(evt) {
const url = evt.clipboardData.getData(“text”) || “”;
// you can check url by regexp
location.href = url; // go away to url
}
}
</script>

That code is just for the requirements - after paste url. Not when write text in input, but just after paste.
Hope this help you.

Solution 3:

I found a way to make this work.

I changed the <InputComponent> tag I had to a normal <input> tag and then added an @change which would link to a method I created.

Below is what I did.

<input placeholder=”Paste the facebook event here” v-model=”facebookPaste” @change=”pastedUrl()” class=”inputFacebook” onkeypress=”return false;”>

export default {
data() {
return {
facebookPaste: ‘’
}
},

methods: {
pastedUrl: function(){
location.replace(this.facebookPaste)
}
}
}

onkeypress=”return false;”: allows me to only paste and not type anything which is what I wanted as well.