Home >Web Front-end >JS Tutorial >Introduction to several methods of opening links in JavaScript

Introduction to several methods of opening links in JavaScript

不言
不言Original
2019-01-14 15:14:2314203browse

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 = '//m.sbmmt.com/blog.html';

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('//m.sbmmt.com/article.html', '_blank');

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('//m.sbmmt.com/article.html', null, 'width=500,height=500');

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;//m.sbmmt.com/article.html&#39;;">

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!

Statement:
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