Welcome to WebmasterWorld Guest from 23.22.250.113

Forum Moderators: open

Message Too Old, No Replies

Redirect to Referring Page

Using Javascript I didn't write

     

Kate82

8:57 pm on Sep 21, 2006 (gmt 0)

10+ Year Member



Okay, so I have never written javascript, and totally don't know anything. But can someone help me figure out how to get my current code to redirect to the page the person was originally trying to reach?

We have a client section that sits behind a veyr easy password scheme. All it requires is the same password from everyone to get in. But then it redirects to the welcome page, no matter what. How do I get it to redirect to the page they were trying to get to?

Here's the code:
<SCRIPT LANGUAGE="JavaScript">
<!--
function setCookie(name, value, expires, path, domain, secure) {
var curCookie = name + "=" + escape(value) +
((expires)? "; expires=" + expires.toGMTString() : "") +
((path)? "; path=" + path : "") +
((domain)? "; domain=" + domain : "") +
((secure)? "; secure" : "");
document.cookie = curCookie;
}
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin!= 0) return null;
} else
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length, end));
}
function deleteCookie(name, path, domain) {
if (getCookie(name)) {
document.cookie = name + "=" +
((path)? "; path=" + path : "") +
((domain)? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
function fixDate(date) {
var base = new Date(0);
var skew = base.getTime();
if (skew > 0)
date.setTime(date.getTime() - skew);
}
function AddCounter() {
var now = new Date();
fixDate(now);
now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
var visits = getCookie("counter");
if (!visits) {
visits = 1;
} else {
visits = parseInt(visits) + 1;
}
setCookie("counter", visits, now);
window.location="http://example.com/support/support_welcome_page.htm";
}
// -->
</SCRIPT>

ahmedtheking

2:45 pm on Sep 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's right at the bottom:

window.location="http://example.com/support/support_welcome_page.htm";

Using JS as a password area? Hmmm not very good! Better to us your server's authentication! Much more secure!

penders

5:25 pm on Sep 23, 2006 (gmt 0)

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



It's right at the bottom:
window.location="http://example.com/support/support_welcome_page.htm";

But I think Kate82 is wanting to redirect the user to 'whatever' page the user was trying to get to, before being directed to the password entry page(?)

It looks like your AddCounter() function is what controls things, it kinda depends where you are calling this function from, but it may be possible to simply pass the Destination Page to this function....

function AddCounter(DestPage) {

And then in the last line, set the window.location to this value, instead of the fixed 'support_welcome_page.htm' as you currently have....

window.location = DestPage;

And then, wherever you call this function (on another page) you pass the URL of the page you want to go to:

AddCounter('/support/pageiwanttogoto.htm'); 
AddCounter(location.href); // The current page

But if you are jumping from page to page, you may need to set your destination page in a Cookie or something and check for that Cookie when you eventually want to get to your intended page.

DrDoc

10:22 pm on Sep 23, 2006 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



the
referrer
may not always be set, but otherwise you should be able to safely redirect there.

Kate82

4:22 pm on Sep 25, 2006 (gmt 0)

10+ Year Member



Thanks everyone! Yeah someday I'll change it to be more secure, have different passwords for different clients, but as of now, this will have to work.

I figured it out with this: javascript:history.go(-2);
replacing the window code.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month