2012-12-09 60 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