jQuery UI对话框显示在框架内,从bookmarklet? [英] jQuery UI dialog display inside frame, from bookmarklet?

查看:207
本文介绍了jQuery UI对话框显示在框架内,从bookmarklet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一本书签,需要在设计不能控制的页面的上下文中工作。一些页面我需要书签功能使用框架(在框架集)。 jQuery-UI对话框可以在框架内工作吗?



目前,当我遇到一个带有框架集的页面时,我创建了如下对话框: p>

  var frame = window.frames [0]; 
var div = $(frame.document.createElement(div));
div.html(我的弹出内容);
div.dialog(...);

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



我知道无法显示覆盖层;我很喜欢在一个框架中显示。另外,一些其他值得注意的书签无法在具有框架集的页面上运行,因此这可能是一个常见问题。



建议?

解决方案

而不是试图在框架内或框架上显示,我只是将书签重新编写页面以删除框架集,并将自己的正文和内容添加到页面。这允许书签仍然内省,并从它们获取需要的数据,以便在删除框架集之前构建叠加层,但允许覆盖层仍然可以工作。



如下所示:

  if(window.frames){
for(var i = 0; i& .frames.length; i ++){
// ...从框架中获取数据...
}
}

if($(frameset )){
$(html)。children(frameset)。remove();
document.body = document.createElement(body);
$(html)。append(document.body);
// ...将我的东西添加到正文...
}


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?

解决方案

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 ...
}

这篇关于jQuery UI对话框显示在框架内,从bookmarklet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆