Mode one if (self.frameelement && self.frameElement.tagName = = "IFRAME") {alert (' in IFRAME ')}//Mode two if (Window.fram Es.length! = parent.frames.length) {alert (' in IFrame ');}//Way three if (self! = top) {alert (' in IFrame ');} first, find parent page element in IFRAME Method: $ (' #id ', window.parent.document) second, get the element method in the IFRAME in the parent page: $ (this). Contents (). Find ("#suggestBox") third, Call the methods and variables defined in the parent page in the IFRAME: Parent.method Parent.value IV, the parent page invokes the JS method within the IFRAME, without having to add an ID to the IFRAME, simply select the IFRAME with JQ to line the $ ("#id"). Find ("iframe") [0].contentwindow.func ()
JS how to determine whether to invoke the IFRAME parent page element and method in the IFRAME/jquery