Home  >  Article  >  Web Front-end  >  Why does Internet Explorer open javascript:void(0)

Why does Internet Explorer open javascript:void(0)

WBOY
WBOYOriginal
2023-05-09 09:59:371768browse

When using the Internet, we often encounter "javascript:void(0)" in web links. This is because in some cases, the IE browser automatically converts the link into JavaScript code, thus preventing The link opens normally. This situation often occurs when using IE browser to access web pages, so what exactly causes IE browser to open "javascript:void(0)"?

1. Missing URL in the link
When the IE browser parses the web page, if it finds that there is no URL in some links, it will convert these links into "javascript:void(0)", indicating This link is not clickable and if the user clicks on it, nothing will happen.

For example, the following code:

Click me

The href in this link is set to "javascript:void(0)", but at the same time There is an alert pop-up box bound to the onclick event, which means that the user clicks on this link and the onclick event is triggered. However, at the same time, due to the ("javascript:void(0)") set in the href attribute, this link will not be executed. Any jump behavior.

2. There are colons in the link
When the IE browser parses the link, if it finds a colon in the link, it will think it is a JavaScript code instead of a standard URL link, so it will convert these links is "javascript:void(0)".

For example, the following code:

Click me

This link is a JavaScript script. An alert pop-up box is set in the onclick event, but because of the link If there is a colon in it, the IE browser will think that this is a piece of JavaScript code rather than a standard link, so it will convert the link into "javascript:void(0)". When this link is clicked, the content in the JavaScript script is called, and Not opening a new page.

3. There is an unsupported protocol in the link
The protocol set in the link must be a protocol supported by the browser, such as http, https, etc. If an unsupported protocol is set in the link, IE The browser will convert this link to "javascript:void(0)".

For example, the following code:

Click me

This link uses the FTP protocol, but the IE browser does not support the FTP protocol, so the IE browser This link will be converted to "javascript:void(0)", making this link unclickable.

In short, when we use IE browser to access a web page, we encounter a situation where the link is converted into "javascript:void(0)". This is usually because there is a missing URL, a colon or an incorrect link in the link. Supported protocols. If you want to solve this problem, just check whether each link has a corresponding URL and whether it uses a supported protocol.

The above is the detailed content of Why does Internet Explorer open javascript:void(0). 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
Previous article:javascript regular escapeNext article:javascript regular escape