隐藏的iFrame:不在历史中显示[jQuery]

时间:2011-05-16 19:41:26

标签: jquery ajax forms iframe history

我在很久以前使用隐藏的iFrame添加了ajax文件上传到我的网站。我在我的网站上使用jQuery,我得到了一切非常快的工作。虽然我无法修复但有一个问题:每次我在iFrame中创建新的ajax请求时,请求的页面都会添加到我的浏览器历史记录中。我知道有很多关于这个主题的问题,但我找不到足够的答案。

我的jQuery代码:

$(document).bind('ready', function() {
    // Add the iFrame to the DOM (iFrame is needed because of file uploads).
    $('body').append('<iframe id="post_form" name="post_form" style="display: none;" src="javascript:false"></iframe>');

    // Show forms on click.
    $('a.own, a.sale, a.spotted').bind('click', function(event) {
        // Animate and clear the boxes.
        $('.box').slideFadeOut(300);
        $('form.' + $(this).attr('class') + ':hidden').delay(300).slideFadeIn(300)[0].reset();

        return false;
    });

    // Get the form response (from iFrame because of file uploads).
    $('iframe#post_form').bind('load', function() {
        var response = $(this).contents().find('body').html()

        if (response.length) {      
            $('div#message').html(response).animate({
                opacity: 'show',
                height: 'show',
                borderWidth: '1px'
            }, 300);
        } else {
            $('.box').slideFadeOut(300);
        }
    });
});

在我的HTML代码中,我将表单的target属性设置为#post_form。我还尝试为每个请求创建一个新的iFrame,或者手动设置frame.location,但是无法将其与文件上传结合使用。有人可以帮忙吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

我认为设定目标不会影响历史。有关详情,请参阅此帖子: Reload an IFRAME without adding to the history

相关问题