Solved

Redirect Traffic To Previous Page

Posted on 2006-06-27
11
182 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
links not working 2 34
Set a parameter in a properties file and use in html table. 14 58
Trying to use &NBSP to line up 3 rows 12 39
Phone number mask 4 13
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

739 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