Welcome to WebmasterWorld Guest from 54.167.86.211

Forum Moderators: open

Message Too Old, No Replies

Redirect to Referring Page

Using Javascript I didn't write

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

Junior Member

10+ Year Member

joined:Jan 13, 2004
posts:67
votes: 0


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>

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 12, 2004
posts: 789
votes: 0


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!

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

Senior Member

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

joined:July 3, 2006
posts: 3123
votes: 0


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.

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

Senior Member

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

joined:Mar 15, 2002
posts:6807
votes: 0


the
referrer
may not always be set, but otherwise you should be able to safely redirect there.
4:22 pm on Sept 25, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 13, 2004
posts:67
votes: 0


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.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members