Reputation: 13
I just want my landing screen to be built in normal JavaScript to reduce the load and redirect to my angular 6 app on click of any buttons in landing screen.
How can I redirect from index.html
to another (Angular) index.html
.
Upvotes: 1
Views: 389
Reputation: 168
Assuming you have multiple buttons on your page, you can trigger a redirect for all the buttons like this:
var buttons= document.getElementsByTagName('button');
for (var i = 0; i < buttons.length; i++) {
var button = buttons[i];
button.onclick = function() {
window.location.href = "https://google.de";
}
}
<button>Button 1</button>
<button>Button 2</button>
<button>Button 3</button>
Upvotes: 1
Reputation: 5031
You can do this by calling the window.location.replace()
method or updating the value of the window.location.href
property.
The calling the window.location.replace()
method simulates a HTTP redirect and updating the value of the window.location.href
property simulates a user clicking on a link.
You would use them as:
// similar behaviour as an HTTP redirect
window.location.replace("index.html");
Or:
// similar behaviour as clicking on a link
window.location.href = "index.html";
You could also create a hidden link and trigger a click on it, like this:
<a href="index.html" style="display: none"></a>
<script type="text/javascript">
document.getElementsByTagName("a")[0].click();
</script>
If you wanted the link to open in a new tab, you'd use the target="_blank"
attribute, like this:
<a href="index.html" style="display: none" target="_blank"></a>
Good luck.
Upvotes: 0