Solved

Navigating to Document Referrer even if window.location used previously

Posted on 2003-12-12
4
642 Views
Last Modified: 2008-02-01
Hi

I need to create a back button which goes to the previous page however history.go dosnt work as I use forms submitting to invisible frames so it sends them back instead of the main screen.  Document referrer was my next thought but it only works if the current page was loaded from an html <a href> and not with a javascript onclick="window.location='';"

Can I get this information when window.location navigation has been used ?

Thanks
0
Comment
Question by:rfila
4 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9929151
If you can use server side code, create your own back button that will post the values back to the previous page. You can then repopulate your fields using the request object.

Fritz the Blank
0
 
LVL 25

Expert Comment

by:devic
ID: 9930567
hi rfila,

all works fine, where is the problem?


===============beginn page1.html==============

<a href=page2.html class=text>click here page2.html</a>

===============end page1.html================





===============beginn page2.html==============

<script>
function runit()
{
      history.back();
}
</script>
<button onclick=runit()>back go back</button>

<form action=http://www.google.com/search target=hidden_iframe>
      <input type=text name=q value=hurra>
      <input type=submit>
</form>
is no hidden for testing:
<iframe name=hidden_iframe></iframe>

===============end page2.html================
0
 
LVL 15

Accepted Solution

by:
JakobA earned 500 total points
ID: 9931989
No.
When you swithc to a new page using javascript, no value is set into document.referrer.

the easiest way around this is to use an invisible link:

at the top of your <body  section:
<body ... >
    <a href=""></a>

then whereever you have a line like
     self.location.href = "newpage.html";
you write instead:
     document.links[0].href = "newpage.html"; document.links[0].click();

it is now the link that sends you on and the referrer property is set when you arrive at the new page.

regards JakobA
0
 
LVL 7

Expert Comment

by:gam3r_3xtr3m3
ID: 9933892
maybe place it into a query string:

main.html
------------
<body onLoad="document.frm1.urlback.value=escape(window.location)">
<form name="frm1" action="next.html" method="get">
<input type="text" name="text1" /><input type="submit" />
<input type="hidden" name="urlback" />
</form>

next.html
-----------
<input type="button" value="Go Back!" onClick="window.location=unescape(window.location.href.split('urlback')[1].split('=')[1]));" />
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

809 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