设置$ _GET值并在href上打开一个新链接

时间:2016-08-28 04:11:14

标签: php html

所以在我的网站上我试图设置一个小按钮,当你点击它时,它会刷新页面来编辑网址,这样就会设置$ _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,但如果不可能,那我就可以采用工作解决方案了

1 个答案:

答案 0 :(得分:0)

你不能只用我能想到的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>
相关问题