Ivan
Ivan

Reputation: 1727

HTML link does not open

I have a test HTML page with a link:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <a href="localhost:8080">Log in with TouchLogin</a>
</body>
</html>

When clicked, the link does nothing. If I add the target = "_blank" attribute, the link opens a new tab, but does not load the URL specified. If I Ctrl-Click it, the link opens fine. What is going on?

Thanks in advance.

Upvotes: 0

Views: 133

Answers (2)

Nick Tirrell
Nick Tirrell

Reputation: 431

Glad you figured it out!

Omitting the http:// will always attempt to open the resource local to where the code originates.

For example, if you're working offline...

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <a href="localhost:8080">Log in with TouchLogin</a>
    </body>
    </html>

Will open something like c://user/parent/localhost:8080

And working online will open something like http://parentsite.com/localhost8080

SO, leave out the http:// when linking to pages on your site but include when linking externally. :)

Upvotes: 1

Ivan
Ivan

Reputation: 1727

Figured it out upon using a different URL in the href(google.com). It did not work without "http://", so I added "http://" to the localhost link and it worked.

Upvotes: 0

Related Questions