Solved

Redirect Traffic To Previous Page

Posted on 2006-06-27
11
180 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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
 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

773 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