2012-12-09 111 views
0

有一個惱人的小問題。找不到解決方案的工作嘗試了一切,我可以找到從搜索這裏和谷歌。動態鏈接/ javascript的重定向/ php

的目的,這是沿着其傳遞到先前已創建了一個「房間」。

好像也無所謂什麼我嘗試,我不能把它加載到使用的onclick帶有href另一頁。我知道它很容易解決它的一些愚蠢的事情,我想不出來。

和抱歉,如果我沒有張貼我的代碼恰到好處,這是我第一次問一個問題,我通常只是潛伏在尋找答案。

//..Left out <?php and my connect info but it is in my script 
//--CLEANUP MY MESS 
$sql = "SHOW TABLES"; 
$result = mysql_query($sql) or die('err11'); 
while ($row = mysql_fetch_row($result)) $testing[$row[0]] = true;// Gets a list of tables in the database and turns them into a handy format 
if ($testing['prim']){// Checks to see if table prim exists 
    $sql = "SELECT * FROM prim"; // Pulling all info again after cleaning 
    $result = mysql_query($sql) or die('err11'); 
    $_e = ''; 
    while ($row = mysql_fetch_assoc($result)){// Cycle through enteries to see what rooms are up 
     $_e = $_e . "<a href='' onclick='join(" . $row['room'] . ");'>" . $row['teach'] ."</a><br>"; 
    } 
}else $_e = "Sorry no rooms are open"; 
mysql_close($con); 
?> 
<!DOCTYPE html> 
<html> 
<head> 
<script> 
function join(er) { 
    alert('ffs is this even firing');//this is a debug statement i was using... it was firing 
    //THE LINE BELOW DOES NOT SEEM TO WORK 
    document.location = "http://***late edit to get rid of the web address lol sorry***start.php?name=" + document.getElementById("name").value + "&room=" + er; 
    //THE LINE ABOVE DOES NOT WORK 
} 
</script> 
<title>Portal</title> 
</head> 
<body> 
Name:<input type="text" id='name' name="name"><br><?php echo $_e ?> 
</body> 
</html> 

我試着像window.location的window.location.href等等等等許多不同的小的變化..也搞砸與回報,只是我發瘋 感謝所有幫助和你們這些人有一個愉快的一天

+0

** Heads up!** PHP的未來版本是*棄用和刪除mysql_'系列函數。現在將是[切換到PDO](http://php.net/book.pdo)或[mysqli](http://php.net/book.mysqli)的好時機。 – Charles

+0

將檢查到tyvm。總是渴望學習新的東西 –

回答

1

window.open會打開一個新窗口,爲您服務。 (見http://www.javascript-coder.com/window-popup/javascript-window-open.phtml

另外,您可以設置href和使用target="_blank"。這樣你就不必使用JavaScript,所以它更容易訪問。

+0

window.open確實工作,並帶他們到下一頁,但是無論如何,我可以不用彈出一個新窗口就可以做到嗎? –

+0

你不能只將鏈接設置爲href?它似乎並不需要JavaScript做任何事情。 'window.location'應該在不打開新頁面的情況下重定向頁面。 – qooplmao

+0

我不知道你會怎麼做,並能夠在地址 –

1

一方面我在想嘗試

<a href='#' onclick=... 

但我會進一步調查。

我的想法是嘗試以下方法,看看它是否有效。

<a href="#" onclick="alert('hi');">hello</a> 

那麼至少會告訴你如果JavaScript在瀏覽器中正常工作等

你可以嘗試從加入到一些其他的名字,因爲加入重新命名它是一個JavaScript函數(對數組操作)也許它有衝突?

+0

試過,作爲其中一個變化我可以發佈所有不同的線我已經嘗試/鏈接到其他文章在這裏我已經嘗試,如果這將幫助。只是不想太多 –

+0

只要你點擊一個使用php創建的鏈接,javascript函數就會觸發警報('ffs甚至會觸發'); –

+0

你可以嘗試alert(「http://www.adulted-northtx.org/provingground/start.php?name=」+ document.getElementById(「name」)。value +「&room =」+ er);並看看它顯示 – user1888773

1

請嘗試以下操作並告訴我它是否有效。然後嘗試在頂部添加一些PHP代碼,看看它是否仍然有效。

<script> 
function test() 
{ 
alert("testing"); 
document.location = "http://location_edited_out/provingground/start.php?name=abcd&room=1"; 
} 
</script> 
<a href="#" onclick="test()">hi</a> 

你可以嘗試的一件事是將腳本移出「頭部」部分並進入正文。

例如:

<html> 
<head><title>Portal</title> 
</head><body> 
<script> 
function join(er) { 
alert('ffs is this even firing');//this is a debug statement i was using... it was firing 
//THE LINE BELOW DOES NOT SEEM TO WORK 
document.location = "http://***late edit to get rid of the web address lol sorry***start.php?name=" + document.getElementById("name").value + "&room=" + er; 
//THE LINE ABOVE DOES NOT WORK 
} 
</script> 
Name:<input type="text" id='name' name="name"><br><?php echo $_e ?> 
</body> 
</html> 

你也可以嘗試把這個腳本在機身的一端(PHP echo命令後)。

你也可以嘗試它分成兩個語句也許不喜歡這樣做的一個行:

var url = "http://webaddr.com/start.php?name=" + document.getElementById("name").value + "&room=" + er; 
document.location = url; 

http://www.webmasterworld.com/javascript/3285118.htm

嘗試window.location.href或簡單地說,location.href top.location

以下在Internet Explorer中工作,有一個按鈕,而不是「一個href」。

<html> 
<body> 
<script> 
function test() 
{ 
alert("testing"); 
window.location.assign("http://location_edited_out/provingground/start.php?name=abcd&room=1") 
} 
</script> 

<input type='button' value='Load new document' onclick='test()'> 
</body></html> 

不知道這是否是一個選項?

因此,代碼爲:

while ($row = mysql_fetch_assoc($result)){// Cycle through enteries to see what rooms are up 
    $_e = $_e . "<input type='button' onclick='join(" . $row['room'] . ");' value='" . $row['teach'] ."'><br>"; 
} 
... 
function join(er) { 
    alert('ffs is this even firing');//this is a debug statement i was using... it was firing 
    window.location.assign("http://***late edit to get rid of the web address lol sorry***start.php?name=" + document.getElementById("name").value + "&room=" + er); 
} 

讓我知道,如果它的工作原理。

+0

這些都沒有竅門。在第一次它彈出測試,但之後坐在同一頁上。第二個人的工作原理與 –

+0

一樣,但錯過了你的最後一行,但是我把它扔到腳本的末尾,並且在它自己的.js中,這兩個都沒有幫助 –

+0

這很有趣!因爲第一個適合我,所以我使用的是Firefox。也許這個問題只發生在Internet Explorer中。 – user1888773