所以在我的网站上,我试图设置一个小按钮,当你点击它,它会刷新页面编辑url,所以$_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>