I am using wind开发者_C百科ow.open("text.html"); to open up file in window.
I want to open another window if first request to window.open is failed ie Page cannot be found message.
like below
if window.open("text.html") = "Page cannot be found" then window.open("message.html"
Regards
As the JinX
said
All I can say is that opening windows is very user unfriendly and blocked by most browsers. Why go that way? – the JinX
Here is a solution to your question.
I have included another method to display a message on that page itself using <div>
.
<html>
<head>
<title>Login</title>
<script>
<!--
function validate() {
var area = document.getElementById("messagearea");
if(document.loginform.username.value == "Ron") {
area.innerHTML = "logged in";
window.open('primegroup.html');
} else {
area.innerHTML = "login failed"; //preffered method to display a message
window.open('regform.html');
}
}
-->
</script>
</head>
<body>
<form name="loginform">
<input type="text" name="username">
<input type="button" value="Login" onclick="validate();">
</form>
<div id="messagearea">
</div>
</body>
</html>
精彩评论