它对我有用,但我需要在同一窗口中打开而不是在新窗口中打开。
这是代码:
<style>
#counter {
padding: 20px;
background: red;
text-shadow: 1px 1px 1px #202020;
font-family: "Lato", sans-serif;
font-size: 18pt;
border: 1px solid lightblue;
color: lightblue;
}
</style>
<?php
$counterFile = 'counter.txt' ;
// jQuery ajax request is sent here
if ( isset($_GET['increase']) )
{
if ( ( $counter = @file_get_contents($counterFile) ) === false ) die('Error : file counter does not exist') ;
file_put_contents($counterFile,++$counter) ;
echo $counter ;
return false ;
}
if ( ! $counter = @file_get_contents($counterFile) )
{
if ( ! $myfile = fopen($counterFile,'w') )
die('Unable to create counter file !!') ;
chmod($counterFile,0644);
file_put_contents($counterFile,0) ;
}
?>
<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
jQuery(document).on('click','a#download',function(){
jQuery('div#counter').html('Loading...') ;
var ajax = jQuery.ajax({
method : 'get',
url : '/data-itai.php', // Link to this page
data : { 'increase' : '1' }
}) ;
ajax.done(function(data){
jQuery('div#counter').html(data) ;
}) ;
ajax.fail(function(data){
alert('ajax fail : url of ajax request is not reachable') ;
}) ;
}) ;
</script>
</head>
<div id="counter"><?php echo $counter ; ?></div>
<a href="" id="download" onclick="window.open(this.href);return false;">Download btn</a>
<style>
#counter {
padding: 20px;
background: red;
text-shadow: 1px 1px 1px #202020;
font-family: "Lato", sans-serif;
font-size: 18pt;
border: 1px solid lightblue;
color: lightblue;
}
</style>
也许与它有关:
onclick="window.open(this.href);return false;"
感谢帮助!!!
最佳答案
这样使用即可在新标签页中打开:
window.open("www.youraddress.com","_self")
要么
替换当前网址:
location.replace("www.youraddress.com");
关于javascript - 我需要它在同一窗口中打开,而不是在新窗口中打开,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51336041/