The link method returns a (italic) string defined using the HTML a tag attribute. The syntax is as follows:
The code copy is as follows:
str_object.link( url )
Parameter description:
| parameter | illustrate |
|---|---|
| str_object | String (object) to operate |
| url | Required. The URL address to which the string is to be linked, in full format. |
Tip: This method does not comply with ECMA standards and is not recommended for use.
Link method example
The code copy is as follows:
<script language="JavaScript">
var str = "www.VeVB.COM";
document.write( str.link( "//www.VeVB.COM" ) );
</script>
Run this example and output:
The code copy is as follows:
www.VeVB.COM
Tip: This method returns a hyperlink string defined using HTML a tag, that is, using this method cannot directly change the string to a hyperlink string. If you want to dynamically change the element font to a hyperlink string, you can refer to the following example to extend the link method:
Change the page element font to a hyperlink
The code copy is as follows:
<html>
<script language="JavaScript">
function addUrl( obj ){
obj.innerHTML = obj.innerHTML.link( "//www.VeVB.COM" );
}
</script>
<body>
<p ondblclick="addUrl(this);">
www.VeVB.COM
</p>
</body>
</html>
In this example, double-click the string www.VeVB.COM with the mouse to add the string to a hyperlink.