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.
Here's the PHP code for getting the value:
<?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
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. 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.