Generate link to external website using a javascript function in angular app

I have a angular application. In the index.html, I have header with some links to external website.

<a href="#" onclick="getUrl('about.html');">click here </a>
<script type="text/javascript">
    function getUrl(link)
    {
        return "https://external-domain.com/"+link;
    }
</script>

but this does not give me desired result as my angular application redirects to localhost:4200 I don’t know why?

Answer

Try to update getUrl function as follows:

<script type="text/javascript">
    function getUrl(link)
    {
    window.location.href = "https://external-domain.com/"+link;
       
    }
</script>

When you will click on the “click here” link it will redirect you to external website successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *