admin管理员组文章数量:1406178
I've made a search bar in my web page and I'm trying to get the user input and pare it to a keyword. If it matches, show the user what he is searching for in another page.
The problem is that I don't know how to switch between pages of the HTML using JavaScript (being in page1.html
and then take the user to page2.html
if the keyword matches).
I've tried to implement href
to a function and then running it when the search button is pressed but I haven't found a way to do it.
Here is the code:
<script>
let search = getElementById("Search").value;
if (search == "Keyword") {
//a href="page2.html" - (this is was my main idea, but i haven't found a way to implement it correctly)
}
</script>
I've made a search bar in my web page and I'm trying to get the user input and pare it to a keyword. If it matches, show the user what he is searching for in another page.
The problem is that I don't know how to switch between pages of the HTML using JavaScript (being in page1.html
and then take the user to page2.html
if the keyword matches).
I've tried to implement href
to a function and then running it when the search button is pressed but I haven't found a way to do it.
Here is the code:
<script>
let search = getElementById("Search").value;
if (search == "Keyword") {
//a href="page2.html" - (this is was my main idea, but i haven't found a way to implement it correctly)
}
</script>
Share
Improve this question
edited Dec 6, 2020 at 21:08
Manu Sampablo
asked Sep 12, 2020 at 18:06
Manu SampabloManu Sampablo
3505 silver badges17 bronze badges
3 Answers
Reset to default 3First, you have to get the value from the input that you create and then you have to pare between the value that you get it and the specific keyword that you want, and after that, you have to create a button to submit with it. Then you can try this line
window.location.href=“./Page2.htm”;
inside if condetion.
try with:
window.location.href=“./Page2.htm”;
You can use
window.open(stringURL);
to open the html in a new window.
To open a new tab:
window.open(stringURL, “_blank”);
For more info: https://developer.mozilla/en-US/docs/Web/API/Window/open
本文标签: How do I switch between HTML pages in JavaScriptStack Overflow
版权声明:本文标题:How do I switch between HTML pages in JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744973179a2635357.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论