繁体   English   中英

如何在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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM