Solved

Redirect Traffic To Previous Page

Posted on 2006-06-27
11
179 Views
Last Modified: 2012-05-05
How do you redirect to a previous page

e.g.

<meta http-equiv='refresh' content='4;URL='javascript:history.go(-1)' />

but obviously this does not work
0
Comment
Question by:doyledom
  • 3
  • 2
  • 2
  • +2
11 Comments
 
LVL 20

Accepted Solution

by:
Gawai earned 25 total points
ID: 16998637
u can use javascript instead

<script>
function Goback() {
history.go(-1);
}
</script>

<body onload="Goback()">

0
 

Author Comment

by:doyledom
ID: 17002439
So how do I call a javascript function in ASP?

Thanks.
0
 

Author Comment

by:doyledom
ID: 17002442
Also, it needs to be delayed for four seconds.
0
 
LVL 2

Assisted Solution

by:bowen18
bowen18 earned 25 total points
ID: 17003095
>"So how do I call a javascript function in ASP?"
Use it like you would any other piece of HTML...just close off the %>

>"Also, it needs to be delayed for four seconds."
To set the delay for four seconds, modify gawai's code to:

<script language="JavaScript">
function Goback() {
history.go(-1);
}
</script>
<body onload="setTimeout('Goback()',4000)">

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Expert Comment

by:Gawai
ID: 17003496
no need to ' sign just

<body onload="setTimeout(Goback(),4000)">
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 17026071
Actually, setTimeout must take a string as its first parameter. Otherwise, it just seems to ignore the time interval and immediately execute the function you include (in IE6 and FF1.5 on Windows OS at least). I'm not knowledgeable enough in Javascript to explain why, unfortunately.

For instance, try running this code in IE6 and/or FF1.5:

<!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" xml:lang="en" lang="en">
<head>
<title>Testing setTimeout</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=ISO-8859-1" />
<script type="text/javascript">
/* <![CDATA[ */

function Goback()
{
    history.go(-1);
}

/* ]]> */
</script>
</head>
<body onload="setTimeout(Goback(), 4000);">
</body>
</html>

Don't worry about the xhtml; I am just trying to get familiar with it, and I probably still made mistakes in either syntax or whatnot. The important part to notice is that there are no quotes surrounding the Goback() function. After running the sample page, try inserting quotes, and notice the difference.

Ted
0
 
LVL 20

Expert Comment

by:Gawai
ID: 17026085
Zyloch, you are making code too complicated. code works fine without all these optional tags.

just

<script language="JavaScript">
function Goback() {
history.go(-1);
}
</script>
<body onload="setTimeout(Goback(),4000)">

no need of all those optional tags u have stated here
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 17026105
I know that :D. I was just practicing my xhtml. But the point I was trying to make is that you do need the quotes around Goback() in setTimeout(). Without them, the second parameter specifying the number of milliseconds to delay is ignored.

Ted
0
 
LVL 19

Expert Comment

by:dakyd
ID: 17142758
<no points for me>

Technically, you're both right and wrong, Ted.  You're right that putting the parentheses around the function call means that it will get executed immediately.  That means that gawai's code will execute onload, rather than 4 seconds after onload.

However, you're wrong in that you *have* to have the quotes.  There are actually two different ways to call setTimeout (and setInterval, for that matter).  One is to pass a function object as the first argument, and the second one is to pass a string.  The first way would look like this:

<html>
<head>
<script type="text/javascript">
function Goback() {
alert("called Goback");
history.go(-1);
}
</script>

<body onload="setTimeout(Goback,4000)">
hello world
</body>
</html>

Notice that there's no paren's for the first argument, so I'm actually passing the function object.  Without the parens, it doesn't execute immediately, and setTimeout knows to execute the function after 4000 milliseconds.

With all that said, bowen looks he/she gave the correct answer first, IMHO.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now