Href of those things

See a problem <a href="">test</a>, then what is the value of href is it? With this question, the beginning of today's topic 'href of those things'.

problem analysis

Why is this?
Last week in the project, msui will page a label binding these events, it will be used href content. href=""So write, it would have been an error. Because the value of the browser at this time to get the absolute path href of the current page. At this time, it will lead to internal msui been an error.

The definition of href

w3c definition

The href attribute on a and area elements must have a value that is a valid URL potentially surrounded by spaces.
Note:The href attribute on a and area elements is not required; when those elements do not have href attributes they do not create hyperlinks.

Roughly translated means:

href attribute on the a and area label must be a valid address RUI
a label area and not necessarily href attribute, no href will not trigger hyperlink features

RUL

w3c definition

A string is a valid non-empty URL if it is a valid URL but it is not the empty string.
A string is a valid URL potentially surrounded by spaces if, after stripping leading and trailing whitespace from it, it is a valid URL.
A string is a valid non-empty URL potentially surrounded by spaces if, after stripping leading and trailing whitespace from it, it is a valid non-empty URL.

Quite a mouthful, the translation does not come out!enter description here

I can understand one of which is a legitimate URL can not be empty. It seems that the URL can be a separate special study.

Solve the problem

From the href URL and definitions can be a good solution to the problem of the beginning. href=""Such an approach is unreasonable, the browser itself will do compatible this case, the default is the absolute address of the page.

Href continue to root out

href content is not only linked to the performance, there are many uses.

Anchor

<a href="#top">头部</a>

In this manner often used for positioning. I believe many people are aware of this usage.

script

<a href="javascript:;"></a>

I believe a lot of this kind of code on many pages. To execute the script with the href.

mail

<a href="mailto:[email protected]">发邮件给我</a>

tel phone

<a href="tel:xxxxxx">打电话给我</a>

sms message

<a href="sms:xxxxxx">发信息给我</a>

In addition, support ftp,fileand so on.

download file

Finally, there is the use of techniques href to download the file, this is the new html5.

<a href="资源地址" download="下载的文件名"></a>

Recently, a demand, consider downloading data via the front table.
Download and use href attribute.

Here as long as the performance of the URL into a data format "data:text/csv;charset=utf-8,\ufeff"+表格数据. After this is completed, etc., write a detailed tutorial points.

to sum up

Written in the last, for href thing is not complete, please add supplement.

Original Address http://xiaoqiang730730.github.io/2016/07/17/href%E9%82%A3%E4%BA%9B%E4%BA%8B/

Guess you like

Origin www.cnblogs.com/homehtml/p/12624572.html