当文档被加载,停止加载如果这个条件不满足
问题描述:
当$(文件)。就绪(函数()停止,如果窗口是提前大于350当文档被加载,停止加载如果这个条件不满足
$(document).ready(function(){
if ($(window).width() > 350){
alert ("No!!! stop");
// I want to stop loading the page altogether if window is less than 350.
return false;
}
else if ($(window).width() < 350) {
alert ("Ok continue.")
}
感谢。
答
$(文件)。就绪(函数()页面后执行被加载。 你可以做到这一点,如果你把你的JavaScript在你的身体上,所以它会执行之前的页面加载
<html>
<body>
<script type='text/javascript'>
//your actions here
//for example redirect to empty page that says stop your width is too large
//another solution is to spam alerts() and if there is no alerts reload page to spam more
//show page with javascript
//$("body').html('STAPH')
</script>
...
</body>
</html>
我可以有像
答
好,我刚添加
$("div").empty();
只是空的所有div如果窗口> 350
请学习'Java'和'javascript'之间的区别,然后再继续。 –
@SotiriosDelimanolis - 我没有在这里看到Java的任何提及?我错过了什么? –
@TravisJ我编辑了出来。 –