Javascript 如何检测我的页面是否加载到div中?
我试图创建一个动态的网站,只有新内容加载,其他元素保持不变。第一个问题: 例如,我想检测我的home.php是否加载到index.php的div中。我该怎么做?因为如果它没有加载到那里,它必须重定向到index.php和home部分。还有第二个问题,如果我刷新页面,它总是默认显示主页。。。 index.php:Javascript 如何检测我的页面是否加载到div中?,javascript,Javascript,我试图创建一个动态的网站,只有新内容加载,其他元素保持不变。第一个问题: 例如,我想检测我的home.php是否加载到index.php的div中。我该怎么做?因为如果它没有加载到那里,它必须重定向到index.php和home部分。还有第二个问题,如果我刷新页面,它总是默认显示主页。。。 index.php: <ul id="nav"> <li><a href="home">Home</a></li> <li&g
<ul id="nav">
<li><a href="home">Home</a></li>
<li><a href="about">About us</a></li>
<li><a href="contact">Contact</a></li>
</ul>
<div id="content"></div>
<script src="js/general.js"></script>
我试过几种方法,但都没有成功
更新:
它不起作用了。但我确信我写的问题是正确的。我想知道如何确定谁直接打开home.php,而不是通过index.php。home.php始终必须重定向到index.php!!并且必须感知打开的菜单。
例如,某人的openhome.php,然后它将他转发到index.php,打开菜单“home”
仅在index.php内显示错误。如果我想阻止home.php直接打开..,正如我在
jquery
文档jquery
中看到的那样,这是没有用的。jquery提供了回调
函数
$('#content').load('' + page + '.php', function(response, status, xhr) {
if (status == "error") {
alert("Sorry but there was an error: ");
} else {
alert("Load was performed.");
}
});
我怎么能反过来做呢?我的意思是,如果没有加载,就执行卸载?此外,jQuery.Load可以直接获取
#内容
,而不是返回整个页面<代码>$(“#content_wrapper”).load(“/page.php#content”,函数(响应、状态、xhr){/*…回调…*/})代码>将用新加载的内容块替换整个内容块。请记住,在完全替换节点时,需要设置#内容块内的任何可能事件(单击等)。-不需要太多的脚本和加载程序检测。
$('#content').load('' + page + '.php', function(response, status, xhr) {
if (status == "error") {
alert("Sorry but there was an error: ");
} else {
alert("Load was performed.");
}
});
$('#content').load('' + page + '.php', function(response, status, xhr) {
if (status == "error") {
alert("Sorry but there was an error: ");
} else {
alert("Load was performed.");
}
});