Solved

Navigating to Document Referrer even if window.location used previously

Posted on 2003-12-12
4
628 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

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

Suggested Solutions

Title # Comments Views Activity
Debugging step-by-step Jquery/Javascript 6 57
CSS Scroll Issue 3 85
rhino JavaScript import, load 25 66
Poster Video HTML 5 Scale to fit video 3 37
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

912 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

17 Experts available now in Live!

Get 1:1 Help Now