Solved

Redirect Traffic To Previous Page

Posted on 2006-06-27
11
183 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

630 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