• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 586
  • Last Modified:

find parent frameset AND preserve page

I've looked all over for something that works, here is my challenge:

If clients search for employee webpages in our site, they can link directly to those pages.  I've put in some javascript to redirect them back to the frameset page:

if (window == top) top.location.href = "../../index.htm";

but I can't find a way to preserve the page they came from.  I've tried using URL strings (e.g., page.htm?id=thispage.htm,

but I'm not allowed to use server-side scripts to process redirects at the other end...meaning I need javascript that preserves the location of the page the clients were trying to access to begin with, or, some reliable way to read a URL string in javascript (I've found some that are either unreliable or too complicated for me)

  • 4
  • 3
1 Solution
Perhaps you can set a cookie to record the location and retrieve it later.

mpalmatiAuthor Commented:
forgot to mention I stink at javascript...
any ideas how???
mpalmatiAuthor Commented:
one other thing, how could I take (what method)

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));

and opent the name cookie in the right frame???
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

first set a cookie from the page the clients get in, write this in the <HEAD> section:

<SCRIPT language="javascript">
 if (parent.location != "http://...your index page"){
   parent.location = "http://...your index page";

function setCookie(name, value, expire)
// sets a value to a cookie
//  (Character string) name is the name of the cookie
//  (void)value is its value
//  (date)expire is the exiration date (may be null)
  document.cookie = name + "=" + escape(value)
   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));

Then in the index page, when opening, you can retrieve the cookie with a function like that:

function getCookie(Name)
// gets the value of a cookie
// (Character String)Name is the name of the cookie.
// The function checks if the cookie exists.
// It returns the value or null
  var search = Name + "=";
  if (document.cookie.length > 0)  // if there are any cookies
    offset = document.cookie.indexOf(search);
    if (offset != -1)  // if cookie exists
      offset += search.length;
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      return unescape(document.cookie.substring(offset, end));
  return null;

and use the JavaScript docuement.write() to open the right page in the right frame if the getCookie(name) returns something :

 MyPage = getCookie(nameofCookie);
 if (MyPage!=""){
   document.write("<frame name'TheName' src='" + MyPage +"' frameborder='no'>");

to be tested of course...
better end with:

  document.write("<frame name='TheName' src='" + MyPage + "' frameborder='no'>");
  document.write("<frame name='TheName' src='TheNormalPage' etc..>;

mpalmatiAuthor Commented:
Thanks for the help ADT, but I found a workaround without using cookies:
I used the writeline method to create the frameset
with a substring condition

     linkURL = "content.htm"
     if (parent.document.URL) {
          callingURL = parent.document.URL
          if (callingURL.indexOf('?') != -1) {
               linkURL = callingURL.substring(callingURL.indexOf('?')+1,callingURL.length)

     document.writeln('<frameset rows="70,395" cols="166,637" frameborder="NO" border="0" framespacing="0"> ')
     document.writeln('<frame src="title.htm" name="title" frameborder="NO" scrolling="NO" bordercolor="#000033">')
     document.writeln('<frame src="header1.html" name="title2" scrolling="NO" frameborder="NO">')
     document.writeln('<frame src="flashdetect.htm" name="nav" scrolling="NO">')
     document.writeln('<FRAME SRC="' + linkURL + '" NAME="content">')

Then pasted the relocation with a string parameter in each individual page:

if (top.location == self.location) {

So simple...too bad I don't bill by the hour...too bad my employer loves frames.

once I figured out the writeln method, I could add whatever script i wanted to the frame source...can't take any credit though:
congrats, you found a better solution and a good address too!


Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now