繁体   English   中英

设置$ _GET值并在href点击上打开新链接

[英]Setting a $_GET value and opening a new link on href click

因此,在我的网站上,我尝试设置一个小按钮,当您单击该按钮时,它将刷新页面以编辑网址,因此将设置$ _GET值,但该按钮还将打开另一个页面。

这是获取值的PHP代码:

<?php
if (isset($_GET['download'])) {
    $downloadingFile = true;
  }
?>

对于按钮,我猜测并尝试了此操作,但没有成功:

<a href="newpage.html" target=_blank href="thispage.php?download=true">download!</a>

有谁知道如何做到这一点? 我希望不要过多地使用AJAX / Java,而只坚持使用HTML / PHP,但是如果那不可能,我愿意采用可行的解决方案

您不能仅凭我无法想到的php真正做到这一点,但是使用jQuery / Javascript相当容易。 我要指出的是,至少您知道自己在做什么:

// When page is finished loading
$(document).ready(function () {
    // When you click a link
    $('a').click(function(e) {
        // Take the event and stop it's natural action
        // (stops link from working)
        e.preventDefault();
        // assign the data attribute from the link
        var getData =   $(this).data('loadnew');
        // Open a new browser window
        window.open(getData,'_blank');
        // Reload this page using the href
        window.location =   $(this).attr("href");
    });
});
</script>

<a target="_blank" href="/this_page.php?download=true" data-loadnew='new_page.php'>download!</a>

的PHP

[英]PHP <a href= click value to cookie

暂无
暂无

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

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