Tuesday, 20 August 2013

Using target attribute is creating issues while opening multiple windows in Safari and Chrome

Using target attribute is creating issues while opening multiple windows
in Safari and Chrome

I have a JSP page where I am trying to open a new link (supoose new link
is: http://www.w3schools.com/) in a new window using the traget attribute
upon submitting the form and I am also opening up another link (suppose
another link is: http://www.google.com/) in the parent window using
javascript. But if I run the code in Safari and Google Chrome, it only
opens the second link (google one), it doesn't open the w3schools link.
Please advise if there is any alternative to target="_blank" or any other
way to open both the windows (When we open both the windows, the focus
should be on w3schools window).
Here is the test JSP page that I have created to demonstrate the issue:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test</title>
</head>
<script language="JavaScript" type="text/javascript">
function redirect(){
document.getElementById("form1").submit();
window.open("http://www.google.com");
}
</script>
<body onload="setTimeout('redirect()', 5000)">
<form id="form1" action="http://www.w3schools.com/" target="_blank">
<a href="javascript:void(0)" onClick="redirect()">Click</a>
</body>
</html>

No comments:

Post a Comment