jQuery UI 对话框显示在框架内,来自书签?

发布于 2024-09-08 05:54:19 字数 690 浏览 1 评论 0原文

我正在编写一个小书签,它需要在我无法控制的设计的页面上下文中工作。我需要小书签才能在使用框架(在框架集中)中运行某些页面。 jQuery-UI 对话框是否可以在框架内工作?

目前,当我遇到带有框架集的页面时,我会像这样创建对话框:

var frame = window.frames[0];
var div = $(frame.document.createElement("div"));
div.html("My popup contents");
div.dialog( ... );

结果是 jQuery 将 ui-widget div 附加到主文档,而不是框架的文档。由于主文档只是一个框架集,因此不会显示任何内容。我在 jquery-ui API 中找不到任何选项来指定应在哪个文档中构建小部件。小书签必须从外部文档的上下文中运行(或至少启动)。

我知道无法在框架上显示覆盖 ;我对仅在单个框架中显示感到满意。此外,一些其他值得注意的小书签无法在具有框架集的页面上运行,因此这可能是一个常见问题。

建议?

I'm writing a bookmarklet which needs to work in the context of pages whose design I don't control. Some of the pages I need the bookmarklet to function in use frames (in framesets). Is it possible for a jQuery-UI dialog to work inside a frame?

Currently, when I encounter a page with a frameset, I creating my dialog like this:

var frame = window.frames[0];
var div = $(frame.document.createElement("div"));
div.html("My popup contents");
div.dialog( ... );

The result is that jQuery appends the ui-widget div to the main document, rather than the frame's document. Since the main document is just a frameset, nothing is displayed. I can't find any options in the jquery-ui API to specify which document the widgets should be constructed in. The bookmarklet will necessarily be running (or at least starting) from within the context of the outer document.

I'm aware that it won't be possible to display an overlay over the frames; I'm comfortable with display just in a single frame. Also, some other notable bookmarklets fail to function on pages with framesets, so this may be a common problem.

Suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蝶…霜飞 2024-09-15 05:54:19

这就是我最终所做的:我没有尝试在框架内或框架上显示,而是让书签重写页面以删除框架集并将我自己的正文和内容添加到页面。这允许小书签仍然内省框架并从框架获取构建覆盖层所需的数据,然后再删除框架集,但允许覆盖层仍然工作。

像这样的东西:

if (window.frames) {
    for (var i = 0; i < window.frames.length; i++) {
        // ... grab data from the frame ...
    }
}

if ($("frameset")) {
    $("html").children("frameset").remove();
    document.body = document.createElement("body");
    $("html").append(document.body);
    // ... add my stuff to body ...
}

Here's what I ended up doing: rather than attempting to display within or over a frame, I just had the bookmarklet rewrite the page to remove the framesets and add my own body and content to the page. This allows the bookmarklet to still introspect the frames and get data that it needs from them to construct the overlay prior to removing the framesets, but allows the overlay to still work.

Something like this:

if (window.frames) {
    for (var i = 0; i < window.frames.length; i++) {
        // ... grab data from the frame ...
    }
}

if ($("frameset")) {
    $("html").children("frameset").remove();
    document.body = document.createElement("body");
    $("html").append(document.body);
    // ... add my stuff to body ...
}
落叶缤纷 2024-09-15 05:54:19

小书签通常不使用 jQuery。大多数书签会打开一个包含 jQuery 的窗口。

Bookmarklets typically don't use jQuery. Most bookmarklets open a window which has jQuery.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文