Thursday, May 26, 2011

Open window in a new browser

There are times when you want to open web page in a new window/browser using Javascript. Before we discuss javascript solution, let me share other ways as well to open new pages using clientend.
It cant get any simpler than this
To view all my post, pleace click here
Code <a href="http://www.qaziarfeen.blogger.com" >here </a>
Code <a href="http://www.qaziarfeen.blogger.com" target="_blank" >here </a>

Using Button
Instead of hyperlinks, we can use HTML buttons as well and make them behave the same way as hyperlinks

Use the following code to test the behaviour to open page in the same window

<input id="btOpen1" type="button" value="Home" onclick="return ClearUrl();" />

<script type="text/javascript" >
function ClearUrl() {

window.location.href = "www.google.com";
}
</script>



Use the following code to test the behaviour to open page in a new window
<input id="btOpen1" type="button" value="Home" onclick="return ClearUrl();" />
<script type="text/javascript" >
function ClearUrl() {
window.open('http://qaziarfeen.blogspot.com'_blank');
}
</script>

No comments: