Open a new Window in JavaScript

How  to Open a new Window in Javascript/using Javascript is easy. Copy below code in your page.

If you want to open a new window on button clik then use below code,
<input type="button" value="Open New Window" onClick="OpenNewWindow('http://www.google.com')" />

If you want to open a new window using hyperlink then use below code,
<a href="javascript:OpenNewWindow('http://www.google.com/')">Open Google</a>

Copy below javascript code between your <head> and </head> tags on the page.
<script type="text/javascript">
        function OpenNewWindow(url)
        {
            newwindow = window.open(url, 'mywindow', 'width=600,height=700'); 
            newwindow.focus();
        }
</script>

No comments:

Post a Comment