开发者

window open and page not found message

开发者 https://www.devze.com 2023-02-12 15:32 出处:网络
I am usingwind开发者_C百科ow.open(\"text.html\");to open up file in window. I want toopen another window if first request to window.open is failed ie Page cannot be found message.

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消