[英]How to open new tab by write some text?
我一直在寻找有关如何通过写确切的单词来打开链接的信息,在我的情况下,这将是“电影”。 我想通过在网站上输入含糊的单词“电影”来打开新链接。
你能给我一些提示吗?
谢谢,
梅吉
您可以使用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://stackoverflow.com/', '_blank');
if (win)
{
win.focus();
}
else
{
alert('Please allow popups for this website');
}
}
}
</script>
</body>
</html>
您可以使用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);" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.