KenyKeny
KenyKeny

Reputation: 151

How to make chrome/firefox able to run parent.frame

I am working on a old web not supporting chrome/firefox. One problem is the code can be run on IE but not chrome/firefox.

 put 'parent.frames("snscont").location.href="../../../../../fts/main/account/INITIAL.html"';

On Chrome,it indicated uncaught type error: parent.frame is not a function. Any jquery or modern code can make this supported chrome/firefox? Thanks a lot.

Upvotes: 0

Views: 2723

Answers (1)

shaochuancs
shaochuancs

Reputation: 16226

You can use the following code to fallback parent.frames to the old IE behavior:

function isFunction(obj) {
  return !!(obj && obj.constructor && obj.call && obj.apply);
}

if (parent.frames && !isFunction(parent.frames)) {
  var originParentFrames = parent.frames;
  parent.frames = function(name) {
    return originParentFrames[name];
  };
}

For your questions in comment:

Why use parent?

Without context of your code, it's hard to answer this question. Basically, parent references the parent of the current window or subframe, if it is invoked on a window that does not have a parent, then it references to itself. You can check https://developer.mozilla.org/en-US/docs/Web/API/Window/parent for more detail (Thanks to @jeetendra's answer).

I guess your code run in an iframe? If that is true, then parent.frames(B) in frame A is a good way to reference iframe B from iframe A.

Is parent an object?

Yes, parent is an object attached on window. You can run typeof parent to get the result object.

What is snscont? Is it a parameter for function frames()?

snscont is the name of your iframe. parent.frames() use name to reference an iframe object. So, yes, it is passed as a parameter.

What does the latter part starting form href means? Is it redirecting to the page listed at the end?

Yes, the ...location.href="..." statement makes the iframe display another URL. But I don't think redirect is the accurate word here.

Upvotes: 1

Related Questions