Thursday, December 16, 2010

JavaScript Basics

javascript to check opened window is closed or not

var win = window.open('http://www.yahoo.com');
alert(win.closed);

return boolean

javascript view webpages' HTML source

<input type="button" value="View" onclick="window.location = 'view-source:'+ 'http://www.royh.cn/'" />
Firefox only?

javascript get user selected text

IE version:
document.selection.createRange().duplicate().text;

Firefox version:
document.getSelection();

For all browser selected():
<input type="button" onclick="alert(selected())" />
<script type="text/javascript">
    function selected(){
        if (document.selection) return document.selection.createRange().duplicate().text;
        else return document.getSelection();
    }
</script>


 

1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Online Training from India. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
    JavaScript Online Training from India

    ReplyDelete