JavaScript link method

JavaScript link method is used to create a hyperlink for any string. While we use the link method it creates hyperlink programmatically.

JavaScript link method

JavaScript link method

     

JavaScript link method is used to create a hyperlink for any string. While we use the link method it creates hyperlink programmatically. This link becomes the element in the array of the document object.

 

 

 

 

 

Syntax:

 stringObject.link( linkURL );

where linkURL is the URL of the web page to which we have to referenced and it also can refer to the JavaScript.

Description of code:

In the following code we have a button and it calls the function createLink() as defined in the JavaScript code within tag <script></script>.

var string = new String('Roseindia Technologies');

Above lines of code creates a string variable and we will be creating link for this string. 

string.link('http://www.roseindia.net');

Above line of code will create a link like that <A HREF="http://www.roseindia.net">RoseIndia Technologies</A>. Here is the full example code for the link method example as given below:

<html>
<body>
<script type="text/javascript" >
function createLink(){
var string = new String('Roseindia Technologies'); 
document.getElementById("div1").innerText = string.link('http://www.roseindia.net');
}
</script>
<center>
<div align="center">
<table border="0" width="45%" bgcolor="#800080">
<tr>
<td width="100%" align="center">
<p align="center"><font face="Comic Sans MS" size="7" color="#FFFFFF">link method</font></td>
</tr>
</table>
</div>
<div id="div1" style="style=width:50%; height:50;background-color:#c9c9ad;"></div>
<input type="button" onclick="createLink();" value="create a link of RoseIndia" />
</body>
</html>

Output :

Click on the button "create a link of RoseIndia" to create link .

Given below is the link from where you can download the full source code.

Download Source Code