homepage Welcome to WebmasterWorld Guest from 54.226.180.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Redirect to Referring Page
Using Javascript I didn't write
Kate82




msg:3092146
 8:57 pm on Sep 21, 2006 (gmt 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>

 

ahmedtheking




msg:3094110
 2:45 pm on Sep 23, 2006 (gmt 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!

penders




msg:3094215
 5:25 pm on Sep 23, 2006 (gmt 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.

DrDoc




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

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




msg:3096128
 4:22 pm on Sep 25, 2006 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved