SimpleModal 在对话框中加载外部 HTML 页面

发布于 2024-08-30 12:39:01 字数 775 浏览 2 评论 0原文

是否可以将外部 HTML 文件加载到变量中,然后使用该变量加载 SimpleModal 对话框?像这样的事情:

$(document).ready(function($) {
    var externalPage $.get("Renderer.htm");

    $('#basic-modal .basic').click(function(e) {
        $(externalPage).modal();

        return false;
    });
});

另一种解决方案(可行)是在隐藏的 div 中加载外部 HTML 文件,然后使用它来加载对话框。

$(document).ready(function($) {
    $('#simplemodal-content').hide(); // or hide in css
    $('#simplemodal-content').load("Renderer.htm");

    $('#basic-modal .basic').click(function(e) {
        $('#simplemodal-content').modal();

        return false;
    });
});

但是,如果我采用这种方法,为外部页面定义的 CSS 可能会干扰我的本地页面,从而更改布局,这是不希望的

如果有比这些方法更好的第三种解决方案,请分享。

PS:遗憾的是它也必须在 IE6 中完美运行。

Is it possible to load an external HTML file into a variable and then use this variable to load the SimpleModal dialog? Something like this:

$(document).ready(function($) {
    var externalPage $.get("Renderer.htm");

    $('#basic-modal .basic').click(function(e) {
        $(externalPage).modal();

        return false;
    });
});

An alternative solution (that works) is loading the external HTML file in a hidden div and then use this to load the dialog.

$(document).ready(function($) {
    $('#simplemodal-content').hide(); // or hide in css
    $('#simplemodal-content').load("Renderer.htm");

    $('#basic-modal .basic').click(function(e) {
        $('#simplemodal-content').modal();

        return false;
    });
});

However if I take this approach the css defined for the external page can interfere with my local page and thus change the layout, which is not desired.

If there's a 3rd solution that's better than these approaches, please share.

PS: sadly it also has to work perfectly in IE6.

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

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

发布评论

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

评论(6

不回头走下去 2024-09-06 12:39:01

我认为您需要使用 iframe 来完成此任务。即使您能够在页面上显示页面内容后将其加载到变量中,它的 css 和 javascript 也会开始影响您的页面。

像这样的东西可能会起作用:

$('#iframeElement').attr('src','Renderer.html')
$('#iframeElement').modal()

虽然您可能不想直接使用 iframe 作为模式对象,但我希望这足以让您指向正确的方向。

I think you will need to use an iframe to accomplish this. Even if you are able to load the contents of the page into a variable once you display it on the page, its css and javascript will start affecting your page.

Something like this might work:

$('#iframeElement').attr('src','Renderer.html')
$('#iframeElement').modal()

Though you will probably not want to use the iframe directly as modal object, but I hope that this is enough to get you pointed in the right direction.

你怎么敢 2024-09-06 12:39:01

不要加载整个 html 文件,而只加载其中的一部分。

$('#simplemodal-content').load('Renderer.htm body');

这将仅加载正文,不包括任何 CSS 或脚本。

Rather than loading the entire html file, load just one part of it.

$('#simplemodal-content').load('Renderer.htm body');

This will load the body only, excluding any CSS or scripts.

零度℉ 2024-09-06 12:39:01

Keare 的答案确实有助于将 css/js 与外部 html 分开,这样它就不会干扰当前页面。它也可以用作模式对话框的基础。

作为替代方案,我还发现了这个解决方案,它在模式对话框本身中使用 iframe。在这种情况下,您可能会遇到滚动条问题,该问题已在此处解决:http://bit.ly/anbyf2

$('#basic-modal .basic').click(function(e) {
    var src = "http://www.google.com";
    $.modal('<iframe src="' + src + '" height="450" width="830" style="border:0">', {
        closeHTML: "",
        containerCss: {
            backgroundColor: "#fff",
            borderColor: "#fff",
            height: 456,
            padding: 0,
            width: 834
        },
        overlayClose: true
    });

    return false;
});

The answer of Keare is indeed useful to seperate the css/js from the external html so it doesn't interfere with the current page. It can also be used as a base for the modal dialog.

As an alternative I've also found this solution which uses an iframe in the modal dialog itself. In this case you might have a problem with scrollbars, which is already solved here: http://bit.ly/anbyf2

$('#basic-modal .basic').click(function(e) {
    var src = "http://www.google.com";
    $.modal('<iframe src="' + src + '" height="450" width="830" style="border:0">', {
        closeHTML: "",
        containerCss: {
            backgroundColor: "#fff",
            borderColor: "#fff",
            height: 456,
            padding: 0,
            width: 834
        },
        overlayClose: true
    });

    return false;
});
只是偏爱你 2024-09-06 12:39:01

虽然滚动您自己的解决方案非常适合学习,并且可能会更有效,但有大量 jQuery 插件可以执行此操作(并已为您解决了所有问题)。示例包括:

http://colorpowered.com/colorbox/http://fancybox.net/

Whilst rolling your own solution is great for learning, and may possibly be more efficient, there are plenty of jQuery plug-ins that do this (and have solved all the problems for you). Examples include:

http://colorpowered.com/colorbox/ and http://fancybox.net/

静水深流 2024-09-06 12:39:01

SimpleModal 网站上的 评论 表明以下代码应该有效:

$.get('page.html', function(data) { $.modal(data); });

A comment on the SimpleModal site indicates that the following code should work:

$.get('page.html', function(data) { $.modal(data); });
沉鱼一梦 2024-09-06 12:39:01
$('#iframeElement').load('Renderer.html');
$('#iframeElement').load('Renderer.html');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文