English 中文(简体)
页: 1
原标题:onBeforeUnload and multiple forms

在用户离开网页时,我只想在网页上提交几种表格。 是否有这种“你拯救吗?”的问题,而我迄今为止的法典就是这样:

function checkForChanges( ) {
  if (window.formform1Changed == true) {
    if (window.asked == false) {
      window.asked=true;
      doSave = confirm("Wanna save? Click OK")
    }
    if (window.doSaveForms || doSave) {
      window.doSaveForms = true;
      document.forms.form1.submit();
    }
  }
  if (window.formform2Changed == true) {
    if (window.asked == false) {
      window.asked=true;
      doSave = confirm("Wanna save? Click OK.")
    }
    if (window.doSaveForms || doSave) {
      window.doSaveForms = true;
      document.forms.form2.submit();
    }
  }
}

这可能似乎有些技能过重,但是由我们的模板发动机自动产生的,而且可能扩大到更多的形式。

The body tag:

<body
 onLoad="init();
         window.formform1Changed=false;
         window.asked=false;
         window.doSaveForms=false;
         window.formform2Changed=false;"
 onbeforeunload="checkForChanges();">

其中一个表格的有趣部分(另一个表格认为:

<input value="xyz" id="la" onchange="window.formform1Changed=true;" />
<input name="save" onclick="window.formform2Changed=false; window.formform1Changed=false;" type="submit" value="save" />

Now to the problem: If I change values in both forms and navigate away from the page, the question from the first form pops up. I click OK, the form is saved but the form1.submit() triggers a new onBeforeUnload event which breaks the whole logic of my idea.

现在的问题是,在用户停机时只问一问一问一问,是否有办法在一页上提交所有表格?

任何帮助都受到高度赞赏!

感谢。

最佳回答

表格提交后需要,一旦您提交第一种表格,您的网页就改用这一表格的“行动”,你将失去你以其他形式提供的信息。

但是,如果你绝对必须掌握这些表格,那么,节省所有表格的方法就是用美国宇宙航空研究开发机构发出的网络服务呼吁(或独立的网页,接受插座参数,尽管这不是安全或灵活的方式)。 这样,你就可以在AJAX号呼吁上提交表格,而不必转页。

问题回答

正如塞拉克所说的那样,你无法以你正在尝试的方式提交多种形式。 你们确实还有其他一些选择。 与传统形式不同的是,你可以发出某种麻醉电话,以挽救你所关心的形式数据。 这方面的一个例子是使用jquery和php(link)





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签