[英]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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.