使用javascript/php动态链接/重定向

使用javascript/php动态链接/重定向,php,javascript,redirect,href,Php,Javascript,Redirect,Href,有烦人的小问题。找不到有效的解决方案,我尝试了在这里搜索和谷歌搜索所能找到的一切 这样做的目的是将它们传递到先前创建的“房间”中 似乎无论我尝试什么,我都无法使用onclick和href将其加载到另一个页面。我知道这是一个很容易解决的问题,只是一些我想不起的愚蠢的事情 很抱歉,如果我没有正确地发布我的代码,这是我第一次问一个问题,我通常只是躲在那里寻找答案 //..Left out <?php and my connect info but it is in my script //--C

有烦人的小问题。找不到有效的解决方案,我尝试了在这里搜索和谷歌搜索所能找到的一切

这样做的目的是将它们传递到先前创建的“房间”中

似乎无论我尝试什么,我都无法使用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>
//…遗漏
函数连接(er){
警报('ffs这是偶发);//这是我使用的调试语句…它正在发
//下面这行似乎不起作用
document.location=“http://***删除网址lol抱歉***start.php?name=“+document.getElementById(“name”).value+”&room=“+er;
//上面这行不行
}
门户
名称:
我尝试了许多不同的小变化,如window.location window.location.href等。。还搞砸了退货,简直把我逼疯了
感谢你们的帮助,祝你们今天过得愉快

首先,我想试试

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

然后,至少这会告诉你javascript是否在你的浏览器上正常工作


您可以尝试将其从join重命名为另一个名称,因为join是一个javascript函数(在数组上操作),可能有冲突?

首先,我想试试

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

然后,至少这会告诉你javascript是否在你的浏览器上正常工作


您可以尝试将其从join重命名为其他名称,因为join是一个javascript函数(在数组上操作),可能有冲突?

窗口。open
将为您打开一个新窗口。(见附件)


或者,您可以设置href并使用
target=“\u blank”
。这样,您就不必使用javascript,因此它更容易访问。

窗口。open
将为您打开一个新窗口。(见附件)


或者,您可以设置href并使用
target=“\u blank”
。这样,您就不必使用javascript,因此更易于访问。

请尝试以下方法,并告诉我它是否有效。然后尝试在顶部添加一些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>

请尝试window.location.href或简单地选择location.href 顶部位置

?

以下内容在internet explorer中使用,使用按钮而不是“a href”


功能测试()
{
警报(“测试”);
window.location.assign(“http://location_edited_out/provingground/start.php?name=abcd&room=1")
}
不确定这是否是一个选项

因此,代码是:

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);
}
while($row=mysql\u fetch\u assoc($result)){//循环浏览条目以查看哪些文件室正在运行
$\u e=$\u e.“
”; } ... 函数连接(er){ 警报('ffs这是偶发);//这是我使用的调试语句…它正在发 window.location.assign(“http://***延迟编辑以删除网址lol抱歉***start.php?name=“+document.getElementById(“name”).value+”&room=“+er”); }

让我知道它是否有效。

试试下面的方法,告诉我它是否有效。然后尝试在顶部添加一些PHP代码,看看它是否仍然有效

<a href="#" onclick="alert('hi');">hello</a>
<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>

请尝试window.location.href或简单地选择location.href 顶部位置

?

以下内容在internet explorer中使用,使用按钮而不是“a href”


功能测试()
{
警报(“测试”);
window.location.assign(“http://location_edited_out/provingground/start.php?name=abcd&room=1")
}
不确定这是否是一个选项

因此,代码是:

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);
}
while($row=mysql\u fetch\u assoc($result)){//循环浏览条目以查看哪些文件室正在运行
$\u e=$\u e.“
”; } ... 函数连接(er){ 警报('ffs这是偶发);//这是我使用的调试语句…它正在发 window.location.assign(“http://***延迟编辑以删除网址lol抱歉***start.php?name=“+document.getElementById(“name”).value+”&room=“+er”); }


让我知道它是否有效。

尝试过,作为其中一种变体,我可以发布我尝试过的所有不同的行/链接到这里我尝试过的其他文章,如果这有帮助的话。只是不想继续太多,每当你点击一个用php创建的链接时,javascript函数就会触发警报(“ffs是偶发的”);您可以尝试警报(“+document.getElementById(“name”).value+”&room=“+er”);看看它正确地显示了什么。呸,我需要编辑那里的地址,我想假设房间和名字没有空格或奇怪的字符,只有A-Za-z0-9,否则需要转义,作为变体之一,我可以在这里发布我尝试过的所有不同行/链接到我尝试过的其他文章,如果这有帮助的话。只是不想继续太多,每当你点击一个用php创建的链接时,javascript函数就会触发警报(“ffs是偶发的”);您可以尝试警报(“+document.getElementById(“name”).value+”&room=“+er”);看看它正确地显示了什么。呸,我需要编辑出那里的地址,我想假设房间和名字没有空格或奇怪的字符,只有A-Za-z0-9,否则它需要转义窗口。open确实有效,并将它们带到下一页,但是否还有其他方法,我可以不必弹出新窗口就可以这样做?你不能将链接设置为href吗?它似乎不需要javascript对其进行任何操作
window.location
应该在不打开新页面的情况下重定向页面。我不知道您将如何做到这一点,并且能够将““name=“+document.getElementById(“name”).value”部分添加到地址中。我没有看到“name”部分,我可能应该更专注于.window.location('blah blah blah'))应该能用。我试着打开窗户的时候,它不起作用。它就在那儿
<a href="#" onclick="alert('hi');">hello</a>