0

I can click "Open 1" button to open a full link in a new tab in Chrome.

When I click "Open 2" button, I can't open a the link without http or https, the browser URL address displays http://localhost:53484/www.google.com.

How can I fix it?

Code A

<html>
<head>
    <script src="Js/jquery-3.6.3.min.js"></script>

    <script type="text/javascript">

        function open1() {
            window.open('http://www.google.com')
        }

        function open2() {
            window.open('www.google.com')
        }
    </script>
</head>

<body>

    <input type=button value="Open 1" onclick="open1()">

    <input type=button value="Open 2" onclick="open2()">

</body>

</html>
2
  • 2
    You can fix it by using a complete URL. Commented Dec 30, 2022 at 1:21
  • I think it has answers here stackoverflow.com/questions/29684740/… Commented Dec 30, 2022 at 1:23

1 Answer 1

1

http or https are needed to open an external link (i.e. to access any website in the world wide web) – it won't ever work without this, this is the official protocol. So if you have a link without it, every browser will automatically add it.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! But the browser add http://localhost:53484 before www.google.com
@HelloCW the browser is assuming you're trying to open a relative path. Using http* will tell it that you are opening an absolute one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.