Search code examples
htmlanchor

Why is my anchor href path, appending to the URL?


I'm utterly baffled by the following situation I find myself in and truthfully, I have no idea why the following is occurring or how to solve the issue.

Here's what's happening;

I have the following anchor;

<a href=”https://www.google.com/intl/en/policies/terms”
   rel="nofollow"
   target="_blank">
   Terms
</a>

If the user clicks this anchor it results in the following URL: https://www.example.com/contact/"https:/policies.google.com/terms

Naturally I was expecting the following URL to be loaded; https://policies.google.com/terms

At first I thought it might be a syntax error, somewhere, so pulled the anchors and checked the code. I can't see any errors anywhere. From there, I tested other links in the page. (All are working fine.) So I thought 'well if they are working, maybe it was a typo in the code?', I rewrote the anchors and the same issue still occurs (strange).

So my second thought was the URL has to be weird somehow, so I used a couple of substitutes, www.google.com, www.youtube.com, and www.facebook.com. All URLs resulted in the same result. Is the target href="" simply being appended to the URL?

I'm not doing anything fancy with my URLs, or JavaScript so why is this occurring? Has anyone ever encountered this? Or maybe a better question would be: How would one debug something like this?


Solution

  • You used incorrect double quotation marks. Take a look very closely at the HTML tags below:

    <p class="text-muted">We'll get back to you within 1-2 business days.</p>
    <p class="small text-muted">(This site is protected by reCAPTCHA and the <br>Google
    <a href=”https://www.google.com/intl/en/policies/privacy” rel="nofollow" target="_blank">Privacy Policy</a> and
    <a href=”https://www.google.com/intl/en/policies/terms” rel="nofollow" target="_blank">Terms of Service</a> apply.)</p>
    

    The quote used in p tag is " and it is different with the one used in the a tag, which is .

    You need to replace it with ".

    <p class="text-muted">We'll get back to you within 1-2 business days.</p>
    <p class="small text-muted">(This site is protected by reCAPTCHA and the <br>Google
    <a href="https://www.google.com/intl/en/policies/privacy" rel="nofollow" target="_blank">Privacy Policy</a> and
    <a href="https://www.google.com/intl/en/policies/terms" rel="nofollow" target="_blank">Terms of Service</a> apply.)</p>