如何通过编写一些文本来打开新标签?

问题描述:

我一直在寻找一些关于如何通过编写确切的词来打开链接的信息,在我的情况下它将是“电影”。我想通过在网站上写入输入元素词 - “电影”来打开新的链接。如何通过编写一些文本来打开新标签?

你能给我一些提示吗?

谢谢
鲇鱼

+0

写字的地方网站上?一些输入元素? – abhishekkannojia

+0

我想通过在网站上写入输入元素词 - “电影”来打开新的链接。 –

+0

@MagdalenaDering请将您的评论添加到您的问题中。这可以防止误解。 – reporter

可以使用onInput或者也可以使用onkeyup事件,打开一个新的标签与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://*.com/', '_blank'); 
     if (win) 
     {   
      win.focus(); 
     } 
     else 
     {   
      alert('Please allow popups for this website'); 
     } 
    } 
} 
</script> 

</body> 
</html> 
+0

我用上面的例子,由起亚完成,我改变了我的需要。一切工作都很好。非常感谢你。 –

可以使用onkeyup事件。

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);" />

+0

谢谢,Jaydeep Mor –