1

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.

Malekai
  • 4,765
  • 5
  • 25
  • 60
Nirmal
  • 13
  • 9
  • Possible duplicate of [How do I redirect to another webpage?](https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage) – Malekai Apr 12 '19 at 11:44

2 Answers2

1

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>
yougeen
  • 168
  • 1
  • 14
0

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.

Malekai
  • 4,765
  • 5
  • 25
  • 60
  • But how can we redirect to the build file of angular from outside. – Nirmal Apr 13 '19 at 11:26
  • What do you mean, can't you just use a regular link like `Example Link`? – Malekai Apr 13 '19 at 11:28
  • Ya got it. But can i pass any parameter in the url to check which button clicked in the angular part – Nirmal Apr 15 '19 at 06:24
  • I don't really see why you shouldn't be able to. – Malekai Apr 15 '19 at 06:55
  • In the angular side our routing will be { path: '', pathMatch: 'full', component: AppComponent }, where as we want to distinguish the button value from the other index html. Lets say i passed -> window.location.replace("a/index.html/frompage/buttonVlaue") from my landing page, the routing is not getting corrected even if i change the route to { path: 'fromPage/:pageValue', pathMatch: 'full', component: AppComponent }, – Nirmal Apr 15 '19 at 07:29
  • I think you would be better off creating a new question with your specific code problem where you can get dedicated help for that solution. – Malekai Apr 15 '19 at 10:02