Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

runtime.getFrameId()

Returns the frame ID of any window global or frame element when called from a content script or extension page, including background pages.

Syntax

js
let gettingInfo = browser.runtime.getFrameId(  target               // object)

Parameters

target

AWindowProxy or abrowsing context containerElement (iframe, frame, embed, or object) for the target frame.

Return value

Returns the frame ID of the target frame, or -1 if the frame doesn't exist.

Examples

This code recursively walks descendant frames and gets parent frame IDs.

js
const parents = {};function visit(win) {  const frameId = browser.runtime.getFrameId(win);  const parentId = browser.runtime.getFrameId(win.parent);  parents[frameId] = win.parent !== win ? parentId : -1;  try {    const frameEl = browser.runtime.getFrameId(win.frameElement);    browser.test.assertEq(frameId, frameEl, "frameElement id correct");  } catch (e) {    // Can't access a cross-origin .frameElement.  }  for (const frame of win.frames) {    visit(frame);  }}visit(window);

Browser compatibility

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp