Search code examples
javascriptanchorhref

href value is being appended after the server name


I am specifying Please visit <a href="www.yahoo.com">Yahoo</a> and the browser appends the server name in front e.g. https://susref.congnos.com/www.yahoo.com

Should I change my href to <a href="https:\\www.yahoo.com">Yahoo</a> will solve the issue?


Solution

  • You need to specify the scheme e.g.

    <a href="http://www.yahoo.com">Please visit Yahoo</a>
    

    Instead of

    <a href="www.yahoo.com">Please visit Yahoo</a>
    

    Without the scheme (the http:// bit) the browser assumes the link is relative to your site