Saturday, January 28, 2012

link() Method in JavaScript

 
The link() method is used to display a string as a hyperlink.
This method returns the string embedded in the <a> tag,
like this: 

<a href="url">string here!!</a>

Syntax:

string.link(url);

JavaScript code:

<script language="javascript" type="text/javascript">
    function myUrl() {
        var myString = new String('Home Page');
        document.write(myString.link('http://anildroisys.blogspot.com/'));
    }
</script>

Html Code:
<button onclick="this.myurl();">Create a link from here! </button>

blure() and assign() Method in JavaScript

blure() Method in JavaScript
 
The blur() method is used to remove focus from an element.
 
JavaScript Code:
 
<script language="JavaScript">
 
function removeFocus(){
   document.getElementById("removeButton").blur();
   document.getElementById("removeButton").innerText = "Its focus!";
   alert("Its focus!"); 
} 
</script>
 
HTML Code:
 
<input id="removeButton" 
       type="button" 
       onclick="removeFocus();" 
       value="Input Focus!" 
       onFocus="this.innerText='In focus. Click me to lose focus'" />
 
 
assign() Method in JavaScript
 
The assign() method loads a new document.
 
JavaScript Code:
 
<script language="JavaScript">
    function newdoc()
    {
        location.assign("http://anildroisys.blogspot.com/");
    }
</script>
 
HTML Code:
<input type="button" value="Load new page" onclick="this.newdoc();" />

pow() Method


The pow() method returns the value of X to the power of Y .

JavaScript Code:

<script type="text/javascript" language="javascript">

    function powFun()
    {
        alert(Math.pow(3, 3));
    }

</script>

HTML Code:

<button onclick="this.powFun();" id="powid" value="Click here!" />