View Full Version : load a new URL
shashgo
10-22-2002, 03:45 AM
Hi,
I am trying to load a new URL into the current window. I have read most of the stuff there is about this, but I am still not clear what to do.
I have used the location property, location.href property, but netiher worked
What I want to do is something like
if (user=="abcdef")
location="images.htm";
else
alert("Wrong user");
How do I make this work?
glenngv
10-22-2002, 03:50 AM
can you post the whole code to see where you're doing wrong?
chrismiceli
10-22-2002, 03:53 AM
if (user=="abcdef") {
parent.location.href="images.html"
}
else
alert("Wrong user");
shashgo
10-22-2002, 03:40 PM
Glenn,
The code I have should work acording to the following
Example 1. The following two statements are equivalent and set the URL of the current window to the Netscape home page:
window.location.href="http://home.netscape.com/"
window.location="http://home.netscape.com/"
that I got from the site at
http://developer.netscape.com/docs/manuals/communicator/jsref/index.htm
My code is
--------------------
if (user=="xyz")
{
window.location="images.html"
}
else
alert("Wrong user");
----------
chrismiceli,
I tried your code too but I couldnt get it to work.
The entire script I have is
<html>
<head>
<title>Authorize</title>
<script language="javascript">
function validate()
{
var user=document.frm.user.value;
var pword=document.frm.pword.value;
if (user=="xyz)
{
alert("Authenticated");
window.location="images.html"
}
else
{
alert("The username\/password you entered is wrong.\n Please re-enter.");
document.frm.user.focus();
return;
}
}
</script>
</head>
<body>
<table rows="3" cols="2" border="1">
<tr>
<td width="14%" bgcolor="ff66ff" align="center"><font face="Arial" size="15" color="#336699">SGE</td>
<td bgcolor="ffccff" align="center"><font face="Arial" size="15" color="#336699">SG ENTERPRISES</td>
</tr>
<tr>
<td bgcolor="ff00ff" rowspan="2" valign="top">
<table rows="1" cols="1">
<tr><td width="100%"><font color="#ffffff"><a href="index.htm">Home</a></td></tr>
</table>
</td>
<td bgcolor="#ffffcc">
<table rows="3" cols="2" name="auth">
<form name="frm" onSubmit="validate()">
<tr>
<td>Username</td>
<td><input type="text" size="30" name="user"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="pword" size="30"></td>
<tr>
<td colspan="3" align="center"><input type="submit"></td>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
------------
Whats going on here?
ptbernar
10-23-2002, 01:40 AM
Well, in the following code, you were missing a closing quotation mark, which may have contributed to your problems. Also, have you tried the reload() function? It is not recognized by IE 5.0 I know, but if you're using browsers later than this it will work fine.
So make the following changes:
if (user=="xyz" )
{
alert("Authenticated");
window.location="images.html";
window.location.reload();
}
Hope this helps.
glenngv
10-23-2002, 02:05 AM
ptbernar, location.reload() is supported by IE5.0
it refreshes the page, it seems that you don't know
what that is, coz it is not needed in this function. :)
anyway this should work:
<html>
<head>
<title>Authorize</title>
<script language="javascript">
function validate()
{
var user=document.frm.user.value;
var pword=document.frm.pword.value;
if (user=="xyz")
{
alert("Authenticated");
window.location="images.html"
}
else
{
alert("The username\/password you entered is wrong.\n Please re-enter.");
document.frm.user.focus();
return ;
}
}
</script>
</head>
<body>
...
<form name="frm">
...
<input type="button" value="Submit" onclick="validate()">
...
but shashgo, using javascript is not a good password validation (but you're not even validating the password, only the username!), the user can just view the source and see the correct value.
what you need is a server-side validation like ASP, PHP where the usernames and passwords are stored in the database.
shashgo
10-23-2002, 04:30 PM
Glenn,
I am not validating the password in the script I provided, but on the one I have I am
if ((user=="xyz"&&(pword="abc")
{
.....
I know that server side validation is better, but I dont see how the validation scheme would be compromised if I put the whole validation routine in an external .js file. It works properly and there is no way the user can see whats in that js file, is there?
Also, the main point of the question I had was I have window.location in my code used just like you have written, but I cant get it to work. I have the images.htm (Note: htm not html) file in th same directory, so it should load. Why is it not working?
All I get is a status line in the status bar that says 'Done', while the screen shows th same authorize textboxes and not the new page.
Something fishy I think. What is it?
redhead
10-23-2002, 05:03 PM
<script>
if (user=="abc" && password=="xyz") {window.location.href="images.htm"
} else {
alert('Wrong User');
};
</script>
that should work... but you still need to say what the variable values (of "user" and "password") are.
if you store the script in an external *.js then anyone can download the script and see whats in it.
:thumbsup:
shashgo
10-24-2002, 02:07 AM
redhead,
But if I store the script in an external .js file, how will users be able to download that fil? Isnt it stored on a server where they would have to be able to put in my username and password in order to get to it?
redhead
10-24-2002, 06:19 PM
Isnt it stored on a server where they would have to be able to put in my username and password in order to get to it?
nope... the user would just go to www.yoursite.com/external.js in Internet Explorer or whatever and it would download as if it were a .zip file.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.