7

Open a URL in a new tab in jQuery

 1 year ago
source link: https://www.laravelcode.com/post/open-a-url-in-a-new-tab-in-jquery
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Open a URL in a new tab in jQuery

  246 views

  5 months ago

jQuery

Generally, external links into website is opened into new tab so user remain into website for further reading. To open link into new tab, we use html attribute target="_blank" method.

Though we can also use Jquery to open link into new tab instead of current tab. In this article, I will show you how to redirect a page in a new tab using jquery.

In the below example, we open the Facebook page into new tab.

<!doctype html>
<html>
<head>
    <title>Open a link into new tab on click using jQuery</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
    <a href="https://www.facebook.com/LaravelCode" id="facebook">Facebook</a>
    <script type="text/javascript">
        $("#facebook").click(function(e) {
            e.preventDefault();
            window.open(this.href);
        });
    </script>
</body>
</html>

So save this file and open it into browser and click on the link. It should open into new tab. I hope it will help you.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK