Friday, September 11, 2009

JavaScript to Open URL in New Window



Sometimes you want to confirm an action before it is carried out. This script displays a confirmation box and, if confirmed, opens the specified URL:


<script type="text/javascript">
function userConfirm()
{
var response=confirm("Do you want to go to the Home page?");
if (response==true)
{
window.open("http://www.yourURL.com/")
}
else
{
alert("User Cancelled!");
}
}
</script>


<a href="http://www.yourURL.com/" onclick="userConfirm()"><img src="http://www.yourURL.com/wp-content/uploads/2009/06/yourImg.jpg" alt="Image Name" title="Image Name" width="115" height="80" class="alignright size-full wp-image-520" /></a>


Click on the graphic below to see how this works:



Image Name

Want HTML Code? Go to: http://write-html-code.blogspot.com/

No comments:

Post a Comment