简体   繁体   中英

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.

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. :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM