Link to home
Start Free TrialLog in
Avatar of abastanpour
abastanpour

asked on

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

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?

Thanks
Avatar of LawrenceAlan
LawrenceAlan

<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>
Avatar of abastanpour

ASKER

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":
<html><head>
<!-- Start new code -->
<script>

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

}
</script>
<!-- End new code -->


ASKER CERTIFIED SOLUTION
Avatar of LawrenceAlan
LawrenceAlan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :)