2011-05-16 57 views
4

我已经添加ajax文件上传到我的网站很久以前使用隐藏的iFrame。我在我的网站上使用jQuery,并且让所有工作都非常快速。有一个问题,但我一直无法解决:每次我在iFrame中发出新的ajax请求时,所请求的页面都会添加到我的浏览器历史记录中。我知道很多关于这个话题的问题,但我找不到足够的答案。隐藏的iFrame:不显示在历史[jQuery]

我的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代码中,我把我的形式的目标属性#post_form。我也尝试为每个请求创建一个新的iFrame,或者手动设置frame.location,但是无法将它与文件上传结合使用。谁能帮忙?

谢谢!

+0

什么是你的问题,这些页面内的历史? – 2011-05-16 19:56:54

+0

它打破了浏览器的后退按钮,用户看到他甚至不知道存在的历史记录中的页面很奇怪。 – Frog 2011-05-16 20:20:25

+0

根据我看到的问题是,您**不使用ajax,您以通常的方式提交表单,所以历史将会增长。你使用闪存上传器,他们不应该影响历史。 – 2011-05-16 20:44:08

回答

0

我相信设置目标不会影响历史。看到这个职位的详细信息: Reload an IFRAME without adding to the history

+0

设置窗体上的目标?我一回到家就会尝试。顺便说一下,我已经发现这篇文章,但由于文件上传,我无法使用iframe.contentWindow.location.replace()。 :( – Frog 2011-05-17 09:49:58

+0

我试图用jQuery动态地设置表单的目标,但是这并不能解决问题,它仍然存在于他的历史中......你还有其他想法吗? – Frog 2011-05-17 19:48:03