2013-10-20 22 views
0

我正在用javascript和jquery設計一款遊戲。在我的遊戲中,當玩家與另一個角色交談時,它會使用window.open('')函數將文本作爲外部文件打開。在遊戲開始時,用戶必須爲他們的角色輸入名字,然後由php處理:
<form action="play.php" method="get">
<input type="text" name="name"/><input type="submit" value="confirm"/>
</form>

正如我以前說過,當一個玩家與另一個玩家談話時,它會打開外部文件,但我所要求的是如何將表單數據傳輸到打開的外部窗口window.open('')我已經試過
function txtone()
{
window.open('txtone.php?name=<?php echo $_GET["name']; ?>')
}

但它沒有工作。所以基本上我最終想要的就是打開一個外部窗口window.open('txtone.php'),它可以從它從
打開的頁面接收php數據(而不是打開txtone.php它會打開txtone.php?name = example)。

編輯:我有一個想法,我可以發送一個PHP變量到window.open打開的子窗口,但我不知道如何用window.opener做這個mabye?將php表單數據傳輸到js窗口

回答

3

你嘗試window.open('txtone.php?name=<?php echo htmlspecialchars($_GET["name"]); ?>')

0
function txtone() { 
    window.open('txtone.php?name=<?= $_GET["name"] ?>'); 
} 
+0

那br應該給我txtone.php?name = <?=%20 $ _GET [「name」]%20?>。 – user2872498

0

當用戶「在日誌中」 - 可以這麼說 - 與你的比賽一開始,他的用戶名,也許嘗試在Cookie中保存名稱和閱讀當他想和別人說話,並把他的名字給JS。

window.open('txtone.php<?php echo $_GET["name'}; ?>') 

^這行有在最後一個錯字(}代替]),也將導致的結果是:

txtone.phpSomeUserName 

你錯過的參數那裏(如果這是在你的代碼像那樣,最有可能是你的罪魁禍首)。也許你打算有類似

txtone.php?username=<?php echo "someUsername"; ?> 
0

你的代碼是有點過

變化

window.open('txtone.php<?php echo $_GET["name'}; ?>') 

window.open('txtone.php<?php echo $_GET['name']; ?>') 

另外,還要確保你傳遞一個值你的名字輸入

相關問題