We help IT Professionals succeed at work.

JavaScript: How do you create a back link to a specific page?

Medium Priority
Last Modified: 2010-08-05
Good day;

I have been using the following JavaScript in my web page, which works rather well:

<a href="javascript:history.back(1)">

Basically, I use the history tag in the above script which takes me to the previous page and it closes the active window.  This is very handy if your active window consists of Frames.
However; I need a link on my web page that closes the active windows (Frames or no frames) and takes you back to a specific page.  How can I do that?  I need no buttons or anything just a typical link.  
Currently, all I have been able to do is go back to the previous page.  Would someone help me with this?

Watch Question

<a href="javascript:document.href='url';">text</a>

ie: <a href="javascript:document.href='http://google.com/';">Google</a>
sorry maybe you should use document.location instead,

<a href="javascript:document.location='url';">text</a>

ie: <a href="javascript:document.location='http://google.com/';">Google</a>


Good day;

Well the document.location works, however it does not close the active window.  I have a page consists of frames and I need it to goto another document.location and close the active window.
Right now when I use the document.location it opens the http://google.com in the middle frame.

We are getting close.. any ideas?
By clear the active window do you mean clear all the frames?

try this:

<a href="javascript:window.location='http://google.com';">Google</a>


I mean to close the active web page being displayed in IE, then open a new IE windows to Google or any other page.
Now, keep in mind that my page is made of three frames.  The code above displays Google in the middle page.  
I need it to clear/close all frames and take me Google or another page.  
Take a look at the web site I am working on: http://www.bradshawestates.com
Navigate to gallery link then hit the previous page link.  You see it closes the gallery page which is a frame.
Now on the gallery page, if you choose to see several pictures and then use the previous windows link, it will take you back to previously looked at picture.  I need it to take me back to the home page.
All the codes that I have seen displays the home page or in your case Google.com in the center frame.
I hope this helps.. Sorry, I don't explain well..  Hope you can help.. :)
Ok this helps, honestly, my suggestion to you is to learn how to use DIVs :) Frames are not well looked upon.

Here's a workaround; Add the script below, and change your link to javascript:goBack();

In "includetopframGall.htm":
<!-- Start new code -->

function goBack() {
var currentURL = new String;
currentURL = parent.window.location + '';
if (currentURL.indexOf('galleryFrame.htm') > -1) {
      parent.window.location = 'http://www.bradshawestates.com/';
} else {

<!-- End new code -->

That script is if you used the same html in the top frame for every page on your site, you could just use:

<a href="javascript:parent.window.location='http://www.bradshawestates.com/';">Previous Page</a>

All depends on how your site is going to work.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Thank you :)
This works very well:  <a href="javascript:parent.window.location='http://www.bradshawestates.com/';">

I do need to understand and learn DIVs:  Not sure where I can start learning about it.  Perhaps an easy editor/software that would walk me through.  If you know one.. Please let me know, and you have any suggestions for our community web site please let me know..

Thank you :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.