如何在windows.location href中插入变量


How to insert a variable in windows.location href?

我尝试过搜索,但没有找到任何在windows.location href="中插入sql变量的解决方案;

我已经试过了:

window.location.href = "<?php echo $up1 ?>"
我在php中找到了一些例子,但在javascript 中没有

但它不起作用,我已经搜索过了,仍然在网上找不到任何东西。

我试过这个例子,但我认为我做的方式不正确。

我的所有代码:

<?php
    $up1 = $userRow['up1'];
    session_start();
    include_once 'dbconnect.php';
    if(!isset($_SESSION['user']))
    {
    	header("Location: index.php");
    }
    mysql_real_escape_string($user_id);
    mysql_real_escape_string($user_name);
    mysql_real_escape_string($user_points);
    mysql_real_escape_string($user_voucher);
    mysql_real_escape_string($user_level);
    mysql_real_escape_string($user_wallet);
    $res=mysql_query("SELECT up1 FROM settings");
    $userRow=mysql_fetch_array($res);
    $up1 = $up1;
    ?>
    <!DOCTYPE html>
    <html>
    <head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
        <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
     </div>
    <script type='text/javascript'>
    document.onkeydown = function (e) {
      var key = e.charCode || e.keyCode;
      if (key == 13) { 
        // enter key do nothing
      } else {
        e.preventDefault();
      }	     
    }
    </script>
    <script>
            window.oncontextmenu = function () {
                console.log("Right Click Disabled");
                return false;
            }
        </script>
    <script type="text/javascript"> 
    function disableselect(e){  
    return false  
    }  
    function reEnable(){  
    return true  
    }  
    //if IE4+  
    document.onselectstart=new Function ("return false")  
    document.oncontextmenu=new Function ("return false")  
    //if NS6  
    if (window.sidebar){  
    document.onmousedown=disableselect  
    document.onclick=reEnable  
    }
    </script>
    <meta charset=utf-8 />
    <title>JS Bin</title>
    </head>
    <body>
<div  id='exemple' data-up='<?php echo $up1;?>'>
    <script>
    function goToBing() {
     //window.location.href = "<?php echo $up1; ?>"
    var test=$("#exemple").attr('data-up);
       window.location.href=test;
    }
    </script>
    <br>
    <br>
    <br>
    <br>
    <center><a href="http://bitcoinrotator.publiadds.org.pt" onclick="goToBing();return false;">Click To Confirm Please</a></center>
    </body>
    </html>

您可以使用:

 <div  id='exemple' data-up='<?php echo $up1;?>'>
 </div>

在jquery中:

var test=$("#exemple").attr('data-up);
   window.location.href=test;