2015-02-09 77 views
-1

好了,我有一種形式,它允許用戶做出事件的預訂如下:爲什麼我的javascript window.opener.location.reload重新加載不同的URL?

<h3>Booking Form</h3> 
<p><form method="post" action="/heroes-and-heroines-larp-and-lrp-events.php?task=submitBooking" class="bookingForm"> 
<label for="role">Booking:</label> 
<select name="role" id="role"> 
<option value="Player">Play</option> 
<option value="Monster">Monster</option> 
<option value="MIA">Unable to Attend</option> 
<option value="Referee">Referee</option> 
</select><br /> 
<div id="AttendeeName"><label for="bookingName">Attendee Name:</label><select name="bookingName" id="listedBookingName"> 
<option value="1">3rd spearman</option> 
<option value="2">4th spearman</option> 
</select></div> 
<div id="CharacterName"><label for="characterName">Character Name:</label><select name="CharacterName" id="listedCharacterName"> 
<option value="1">Jack Dawkins</option> 
<option value="2">Reverand Blighty Shrewson</option> 
<option value="3">Sydion</option> 
**</select><button class="button" onClick="window.open('http://www.heroesandheroines.org/index.php?task=siteForm', '', 'width=500, height=500');"><span class="formButton">create a new character</span>**</button></div> 
<div id="telephoneNumber"><label for="telephone">Telephone Number:</label> 
<input required type="tel" id="telephone" name="telephone" value="" /></div> 
<div id="emailAddress"><label for="email">E-mail Address:</label> 
<input required type="email" id="email" name="email" value="[email protected]" /></div> 
<div id="notes"><label for="notes">Notes:</label> 
<textarea id="notes" name="notes" rows="4" cols="50" placeholder="notes" /></textarea> 
</div><input type="hidden" name="returnPage" value="http://heroesandheroines.org/heroes-and-heroines-larp-and-lrp-events/124_tbc.html" /> 
<input type="hidden" name="dungeonid" value="124" /> 
<input type="submit" name="submit Booking" value="Submit Booking" /> 
&nbsp;<a href="">CANCEL</a></p> 
</form> 

按鈕<button class="button" onClick="window.open('http://www.heroesandheroines.org/index.php?task=siteForm', '', 'width=500, height=500');">火災打開一個新的窗口,它允許用戶創造出一個新的字符在事件上使用。

新窗口中有如下因素的javascript:

<script> 
    window.onunload = refreshParent; 
    function refreshParent() { 
     window.opener.location.reload() 
    } 
</script> 

現在,它的工作正在進行中,但我要的是子窗口刷新父窗口,然而,子窗口不刷新父窗口的原始內容(http://heroesandheroines.org/heroes-and-heroines-larp-and-lrp-events.php?task=bookingForm&eventID=124)...它加載http://heroesandheroines.org/heroes-and-heroines-larp-and-lrp-events.php?task=submitBooking這是窗體的目標...如何獲取父窗口刷新其URL而不是表單提交URL?

另外,我很困惑,爲什麼它的行爲是這樣的...肯定window.opener.location.reload應該只是刷新頁面從請求的URI或什麼?

+0

'行動=「/英雄,和女主角 - 叻和-LRP事件.php?task = submitBooking「'您的'表單'正在提交,因此'URL'正在更改。 – melancia 2015-02-09 17:31:18

回答

0

A <button>有一個type attribute,默認爲submit。 IE當你點擊你的按鈕,以及打開新窗口時,它也會在後臺提交表單,這會更新你的URL。添加在type屬性您的按鈕,並將其指定爲button - 這將在後臺提交停止形式:

<button type="button" class="button" onClick="window.open('http://www.heroesandheroines.org/index.php?task=siteForm', '', 'width=500, height=500');"> 
+1

作爲一個附錄:這看起來不像偉大的用戶體驗 - 如果用戶在表單中做了一些工作,然後單擊該按鈕,當該窗口關閉時,頁面將重新加載並且用戶將丟失迄今爲止輸入的任何內容 – 2015-02-09 17:34:56

+0

是的,我只是在它的中間,所以這只是一個正在進行的工作,但這是我沒有想到的一個好點!基本上,用戶將使用彈出框創建新角色,提交表單(觸發'refreshParent'功能),然後我需要將該新角色添加到下拉字符'characterName',但我沒有想過事實上,這將消除他們在形式上所做的所有工作......該死!感謝您的提示,並感謝完美的解決方案! :) – 2015-02-09 17:47:24

相關問題