Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


find parent frameset AND preserve page

Posted on 2003-02-27
Medium Priority
Last Modified: 2013-11-19
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)

Question by:mpalmati
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3

Expert Comment

ID: 8036476
Perhaps you can set a cookie to record the location and retrieve it later.


Author Comment

ID: 8037076
forgot to mention I stink at javascript...
any ideas how???

Author Comment

ID: 8037143
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???
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.


Accepted Solution

ADT earned 400 total points
ID: 8037516
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...

Expert Comment

ID: 8037571
better end with:

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


Author Comment

ID: 8037942
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:

Expert Comment

ID: 8038091
congrats, you found a better solution and a good address too!


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

722 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