隐藏的 iFrame:不显示在历史记录中 [jQuery]
我很久以前就使用隐藏的 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,但无法将其与文件上传结合使用。有人可以帮忙吗?
谢谢!
I've added ajax file uploads to my site quite some time ago using a hidden iFrame. I use jQuery on my site and I got everything to work really fast. There's one problem though that I haven't been able to fix: every time I make a new ajax request in my iFrame the requested page is added to my browsers history. I know quite a bit of questions have been asked on this topic, but I couldn't find a sufficient answer.
My jQuery code:
$(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);
}
});
});
In my HTML code I've set the target attribute of my form to #post_form
. I also tried to create a new iFrame for every request or set the frame.location manually, but couldn't get that to work in combination with file uploads. Can anyone help?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论