How to redirect from a normal JavaScript page to angular 6(microsite to angular 6)?

354 Views Asked by At

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.

2

There are 2 best solutions below

6
On

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.

0
On

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>