简体   繁体   English

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

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

so in my website I'm trying to set up a little button where when you click it, it'll refresh the page to edit the url so a $_GET value will be set but the button will also open another page. 因此,在我的网站上,我尝试设置一个小按钮,当您单击该按钮时,它将刷新页面以编辑网址,因此将设置$ _GET值,但该按钮还将打开另一个页面。

Here's the PHP code for getting the value: 这是获取值的PHP代码:

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

For the button I guessed and tried this but it didnt work: 对于按钮,我猜测并尝试了此操作,但没有成功:

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

Does anyone know how to do this? 有谁知道如何做到这一点? I'd prefer to not mess too much with AJAX/Java and just stick with HTML/PHP but if that's not possible I'm open for taking the working solution 我希望不要过多地使用AJAX / Java,而只坚持使用HTML / PHP,但是如果那不可能,我愿意采用可行的解决方案

You can't really do that with just php that I can think of off the top of my head but it's fairly easy with jQuery / Javascript. 您不能仅凭我无法想到的php真正做到这一点,但是使用jQuery / Javascript相当容易。 I will notate so at least you know what things are doing: 我要指出的是,至少您知道自己在做什么:

// 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>

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

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