[英]How do i make my page blank with a query?
If I set the URL to exmaple.com?blank=true a blank page should be presented.如果我将 URL 设置为 exmaple.com?blank=true,则应显示空白页面。
Using JavaScript or jQuery i want a short snippet that looks for ?blank=true in the url and if it finds it than the page to turn white or blank.使用 JavaScript 或 jQuery 我想要一个简短的片段,它在 url 中查找 ?blank=true ,如果找到它,页面就会变成白色或空白。
Try like this像这样尝试
var url_string = "https://example.com?blank=true "; //window.location.href var url = new URL(url_string); var blank = url.searchParams.get("blank"); if(blank){ document.getElementsByTagName("body")[0].style.display = "none"; }
<body> <p>this will be hidden</p> </body>
With jQuery使用 jQuery
var blank = /(?<=blank=)[^&?]+/g.exec('https://example.com?blank=true')[0];
if(blank === 'true'){
$('body').hide();
}else{
$('body').show();
}
wrap your html content in a element like this将您的 html 内容包装在这样的元素中
<html>
<body>
<div id="wrapper">
<!-- ********your content here******** -->
</div>
</body>
</html>
use jquery code as使用 jquery 代码作为
$(document).ready(function() {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('=');
if(sURLVariables[0]=="blank" && sURLVariables[1]=="true")
{$('#wrapper').css('display','none');}
else{
$('#wrapper').css('display','block');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.