Home > Web Front-end > JS Tutorial > body text

Introduction to several methods of opening links in JavaScript

不言
Release: 2019-01-14 15:14:23
Original
14148 people have browsed it

How to open a link using Introduction to several methods of opening links in JavaScript? In this article, we will take a look at several methods of opening links using Introduction to several methods of opening links in JavaScript.

Introduction to several methods of opening links in JavaScript

Let’s look at a piece of code first

Use Javascript to open the link. You need to replace the URL of the link to be opened in location.href.

location.href = 'http://www.php.cn/blog.html';
Copy after login

With the above code we can open the specified link.

Let’s continue to look at several ways to open links

How to open links in new tabs

Open links in new tabs, Please replace the URL of the link you want to open in the parameters of window.open.

window.open('http://www.php.cn/article.html', '_blank');
Copy after login

This way I can open a link with a new tab.

How to open a link in a new window

To open a link in a new window, you need to use the window.open parameter to specify the size of the window.

window.open('http://www.php.cn/article.html', null, 'width=500,height=500');
Copy after login

In this way, we can open the link in a new window.

Setting method for the button that opens the link

To set the button that opens the link, you need to specify the onClick event that opens the link to the button.

<input type="button" value="打开链接" onClick="document.location=&#39;http://www.php.cn/article.html&#39;;">
Copy after login

In this way, we can set a button to open the link.

The above is the detailed content of Introduction to several methods of opening links in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!