0

I was looking for some information about how to open link by writing exact word, in my case it will be "film". I want to open new link by writing on website in input elemtent word - "film".

Can you give me some hints?

Thank you,
Megi

Reporter
  • 3,897
  • 5
  • 33
  • 47

2 Answers2

1

You can use the onInput or also use onkeyup Event to open a new tab with window.open

<!DOCTYPE html>
<html>
<body>

Enter keyword: <input id="keywordinput" type="text" value="notfilm" oninput="checkForFilm()">

<script>
function checkForFilm() 
{
    if(document.getElementById('keywordinput').value == 'film')
    {
      var win = window.open('http://stackoverflow.com/', '_blank');
      if (win) 
      {          
          win.focus();
      } 
      else 
      {          
          alert('Please allow popups for this website');
      }
    }
}
</script>

</body>
</html>
Jaydeep Mor
  • 1,690
  • 3
  • 21
  • 39
Kia
  • 301
  • 3
  • 11
1

You can use onkeyup event.

function openLink(e){
  if(e.value == 'film'){
      var new_window = window.open('http://abc.xyz/', '_blank'); // Replace with your link. 
      if(new_window){          
          win.focus();
      }
      else{
          alert("Allow popups from your browser settings.");
      }
  }
}
Enter word : <input type="text" name="input_name" id="input_id" value="" onkeyup="openLink(this);" />
Jaydeep Mor
  • 1,690
  • 3
  • 21
  • 39