Summary of use of src and href

Source: Internet
Author: User
Tags blank page

Src
    • IMG Pictures
    • Rame IFRAME Framework Set<iframe src="girl.gif"></iframe>
    • input type is the submit button for image<input type="image" src="submit.jpg" alt="Submit" align="right" />
    • Scirpt Script<script type="text/javascript" src="org.js"></script>
    • The Style style sheet (SRC attribute is extended to all elements in XHTML2 in the womb). For example, you can: <style src="common.css"> </style> )
Href
    • A<a href="http://www.baidu.com" target="_blank">百度</a>
    • Link references external CSS<link type="text/css" href="iknow_base.css" rel="stylesheet" />
    • The onclick event in input type
      <input type=button onclick="window.location.href(‘#‘)" />

These are the tags that src and href will be used in, and here's a look at their differences.

SRC is the shorthand for source, which means that the content of the element will be replaced as a whole by referencing a resource. If you do not write SRC, then there is no content in itself, script will not exist, and IMG will display a blank page x,iframe. For example <script type= "Text/javascript" src= "B.js" >alert (1) </script>,b.js:alert (2); The standard browser will display 2, because its content has been replaced.

HREF is the abbreviation of hypertext reference, which means "hyperlink", not to reference a resource, but to establish a "channel", so that the current tag can be linked to the target address, not to pull the target into the page itself to replace its own content, For example, the href of a tag is not replaced by itself as a resource, and the link tag itself does not contain the actual element meaning to do the content, it requires a rel explicit representation of what the "connected document does". As for why it was decided that the external stylesheet was linked with the link href instead of the style SRC, it was probably because the sages thought that the stylesheet was more consistent with the characteristics of the external link resource, which was closer to the attached resource than the embedded content.

The above main content is quoted from why the JavaScript is loaded using "src", CSS using "href"? Does it have a meaning or a legacy of historical grammar?


Links: https://www.jianshu.com/p/797bceab922b


href denotes hypertext reference (hypertext Reference) Reference establish contact
SRC indicates the source address of the source is   introduced



There is a difference between src and href, which can be confused and used. SRC is used to replace the current element, and the href is used to establish a connection between the current document and the referencing resource.

SRC is the abbreviation for source, which points to the location of the external resource, which is embedded in the document where the current label is located, and the resources it points to are downloaded and applied to the document when the SRC resource is requested, such as JS scripts, IMG images, and frame elements.

<script src = "js.js" ></script>

When the browser resolves to the element, it pauses the download and processing of other resources until the resource is loaded, compiled, executed, and so on, like pictures and frames, similar to embedding the resource in the current tag. This is why the JS script is placed at the bottom instead of the head.

The HREF is the abbreviation for the hypertext reference, which points to the location of the network resource, establishes the link between the current element (anchor point) or the current document (link), and if we add in the document

<link href= "Common.css" rel= "stylesheet"/>

The browser will then recognize the document as a CSS file, and it will download the resources in parallel and will not stop processing the current document. This is why it is recommended to use the link method to load the CSS instead of using the @import method.







As for why it was decided that the external stylesheet was linked with the link href instead of the style SRC, it was probably because the sages thought that the stylesheet was more consistent with the characteristics of the external link resource, which was closer to the attached resource than the embedded content. Consider alternate stylesheets, for example, to link only one set of style sheets at a time, rather than loading them all. Of course you can simply boil down to the legacy of history (an accidental decision by a browser developer).

Links: https://www.zhihu.com/question/19708137/answer/13562191




Summary of use of src and href

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.