繁体   English   中英

我需要它在同一窗口中打开,而不是在新窗口中打开

[英]I need it to open in the same window and not in a new window

它对我有用,但是我需要在同一窗口中打开而不是在新窗口中打开。


这是代码:

  <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;"

感谢帮助!!!

将URL分配给window.location以重新加载当前窗口,而不是打开新窗口。

onclick="window.location = this.href;return false;"

但这是单击链接的默认操作,您无需使用Javascript。

这样使用即可在新标签页中打开:

window.open("www.youraddress.com","_self")

要么

替换当前网址:

location.replace("www.youraddress.com");

暂无
暂无

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

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