3 Replies - 422 Views - Last Post: 22 January 2012 - 11:25 AM

#1 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 282
  • Joined: 29-December 09

Document.Open() will not work[SOLVED]

Posted 21 January 2012 - 07:30 PM

So, I have a button where if the person's username and password is correct, it will notify you, then it will redirect to another page. The first thing works, but it will not redirect you to the page.

Here is the code of the webpage:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Siur</title>
<script type="text/javascript">
///////////////////////////Login System///////////////////////////
function getCookie()
{
	var whole, username, password, splitting, actual,user, pass;
	whole = document.cookie;
	whole = whole.split(';');
	username = whole[0];
	password = whole[1];
	actual = password.split('=');
	user = actual[0];
	pass = actual[1];
	alert(user + password);
}

function setCookie(c_name,value,exdays)
{

var c_value=value + "; pass="+document.getElementById('passwordText').value;
document.cookie="=" + value + "; pass="+document.getElementById('passwordText').value;
alert(document.cookie);
getCookie();
}
function url(url)
{
	  document.open(url);
}
function checkCookie()
{
		var whole, username, password, splitting, actual,user, pass;
	whole = document.cookie;
	whole = whole.split(';');
	username = whole[0];
	password = whole[1];
	actual = password.split('=');
	user = actual[0];
	pass = actual[1];
if (document.getElementById('usernameText').value !=null && document.getElementById('usernameText').value!="" && document.getElementById('passwordText').value == pass)
  {
  alert("Welcome again " + user);
  document.open('search_webpage.html');
  }
else
  {
 alert('Incorrect username or password.');
  }
}
//////////////////////////////End of Login system////////////////////////////////////
</script>
<script type="text/css">
body
{
	font-family:"Arial Black", Gadget, sans-serif
}
</script>

</head>

<body leftmargin="0" topmargin="0" rightmargin="0" style=" font-size:12px; font-family:'Verdana', Geneva, sans-serif">
<table width=100% height=30 bordercolor="#999999" background="nav.png" border="0">
  <tr>
    <td ><form id="form1" name="form1" method="post" action="">
      <label for="searchBox"></label>
      IN-DEV 0.1
      
    </form></td>
  </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>
<center><p><img src="logo.png" width="206" height="147" /></p>
  <p><font color="#CCCCCC">-Where everything is at your finger tips-</font></p>
  <p>
    <label for="usernameText"><label>Username: </label></label>
    <input type="text" name="usernameText" id="usernameText" />
  </p>
  <p>
    <label for="passwordText"><label>Password: </label></label>
    <input type="password" name="passwordText" id="passwordText" />
  </p>
</center>
<center>
  <p>
    <input type="submit" name="create" id="create" onclick="checkCookie()" value="Login" /> 
    <input type="submit" name="check" id="check" onclick="setCookie(document.getElementById('usernameText').value,document.getElementById('passwordText').value,365);" value="Register" />
  </p>
  <p><a href="http://blacklist.eff.org/">Fight SOPA now!</a></p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p><!--[if lt IE 7]> <div style=' clear: both; height: 59px; padding:0 0 0 15px; position: relative;'> <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode"><img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." /></a></div> <![endif]--><footer><font color="#CCCCCC">Copyright 2012, All Rights Reserved.</font></footer></p>
</center>
</body>
</html>



I will keep looking for fixes, but I could not solve the problem.

This post has been edited by CreaturGames: 22 January 2012 - 11:26 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Document.Open() will not work[SOLVED]

#2 thrca  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 28
  • View blog
  • Posts: 65
  • Joined: 21-January 12

Re: Document.Open() will not work[SOLVED]

Posted 21 January 2012 - 08:21 PM

first off, its generally not a real good idea to use a variable name that also refers to a function...

function url(url)
{
      document.open(url); //is url the function or the variable?
}



instead... use
function goto_url(url) {
  window.href.location = url; //I think this might be what you are looking for
}



On a totally seperate note, validating the user's password using javascript is like a bank asking you if your check is good before agreeing to cash it.

my apologies, i meant "window.location.href", but could cause a history loop if they click the back button.. Perhaps better to use "window.location.replace(url)"
Was This Post Helpful? 1
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2890
  • View blog
  • Posts: 7,535
  • Joined: 08-June 10

Re: Document.Open() will not work[SOLVED]

Posted 22 January 2012 - 03:13 AM

View Postthrca, on 22 January 2012 - 04:21 AM, said:

instead... use
function goto_url(url) {
  window.href.location = url; //I think this might be what you are looking for
}

or window.open(url);

what document.open() does:

Mozilla Developer Network said:

The document.open() method opens a document for writing.

If a document exists in the target, this method clears it.

Also, an automatic document.open() call happens when document.write() is called after the page has loaded, but that's not defined in the W3C specification.

Do not confuse this method with window.open(). document.open allows you to overwrite the current document or append to it, while window.open provides a way to open a new window, leaving the current document intact. Since window is the global object, just calling open(...) does the same as window.open(...).

Was This Post Helpful? 1
  • +
  • -

#4 CreaturGames  Icon User is offline

  • D.I.C Regular

Reputation: 30
  • View blog
  • Posts: 282
  • Joined: 29-December 09

Re: Document.Open() will not work[SOLVED]

Posted 22 January 2012 - 11:25 AM

Thank you for all the help. I was taught that document.open() opens another document and displays it, but it seems not.

Well, the solution worked. The login system is still being worked on, for it needs more security factors to it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1