Can someone help me with my codes about the log in using javascript, everytime i log in it opens a new window for the homepage, but i want it to be in the same window, thank you :D

<html>
<head>
<title>
Login page
</title>
</head>
<body background="black_background_metal_hole_very_small-wallpaper-2560x1600.jpg">
<h1 style="font-family:Comic Sans Ms;text-align="center";font-size:20pt;
color:#00FF00;>
<bR>
<center><font face="dodger" color="red">Welcome to Gamebook</font></center>
</h1>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<form name="login">
<h3><center><font face="dodger" color="red">Username:<input type="text" name="userid"/></font></center>
<br>
<center><font face="dodger" color="red">Password:<input type="password" name="pswrd"/></font></center></h3>
<center><input type="button" onclick="check(this.form)" value="Login"/>
<input type="reset" value="Cancel"/></center>
</form>
<script language="javascript">
function check(form)
{
if(form.userid.value == "yakuzajevin" || form.userid.value == "YAKUZAJEVIN" && form.pswrd.value == "yakuzajevin" || form.pswrd.value == "YAKUZAJEVIN")
{
window.open('file:///D:/WEBPAGE/redirect.html')
}
else
{
alert("Access Denied")
}
}
</script>
<SCRIPT LANGUAGE="JavaScript">
var message="Please Log in!";
function clickIE() {if (document.all) {alert(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {alert(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
</script>
<center><font face = " dodger " color = " red ">note: case sensitive!</font>
</body>
</html>

Recommended Answers

All 7 Replies

If you want the web page to open in the same browser window use window.location() instead of window.open()

Member Avatar for iamthwee

Also consider using jquery.

but when i used window.location() it wont work.

the window.location.replace() works, thank you for your replies :D

If you use:

window.location.assign('file:///D:/WEBPAGE/redirect.html');

The 'Back' button in your browser should still be active. I'm not sure if that is what you desire; otherwise, the options suggested by others will replace the current page with the new one.

Regards - Shawn

when i used window.location.assign, it ignores the value required for my password

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.