Javascript 在页面之前加载图像
我有一个页面上有两个来自和两个图像。当页面加载一个表单时,提交页面进行用户验证,并在提交第二个表单并打开站点后重定向回该页面。我想以图像格式显示欢迎信息和等待图像。但是我的页面是在图像加载之前提交的。这是我的第页代码Javascript 在页面之前加载图像,javascript,php,Javascript,Php,我有一个页面上有两个来自和两个图像。当页面加载一个表单时,提交页面进行用户验证,并在提交第二个表单并打开站点后重定向回该页面。我想以图像格式显示欢迎信息和等待图像。但是我的页面是在图像加载之前提交的。这是我的第页代码 <?php $return_url = "index.php?".$_SERVER[QUERY_STRING]; $return = base64_encode($return_url); $headers = apache_request_hea
<?php
$return_url = "index.php?".$_SERVER[QUERY_STRING];
$return = base64_encode($return_url);
$headers = apache_request_headers();
$date_check1 = date('Y-m-d');
$date_check2 = date('d-m-Y');
$auth_confirm = md5('commonauth');
$contextURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$contextURL .= "s";}
$contextURL .= "://";
$http=$contextURL;
$contextURL = $contextURL.$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME'];
if($_SERVER['QUERY_STRING']) $contextURL = $contextURL."?".$_SERVER['QUERY_STRING'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML>
<HEAD>
<TITLE>Welcome to a new world of interaction</TITLE>
<style>
.mainimage {background:url("templates/site1/images/Spotlight_Test.jpg") no-repeat scroll 0 0 #FFFFFF !important;height:212px;width:612px;}
.waitingimage {background:url("templates/site1/images/ajaxLoader.gif") no-repeat scroll 0 0 #FFFFFF !important;height:43px;width:43px;}
</style>
</HEAD>
<script>
function commonAuth(){
if(document.referrer == '<?=$http?>authenticationsite.com/'){
var days = '';
days = '<?php echo $_REQUEST["passwordExpiration"] ?>';
if(days > 0){
document.Form1.submit();
}else{
document.Form2.submit();
}
}else{
if(window.location.hash){
var hs = window.location.hash;
var pos = hs.indexOf('#');
hs = hs.substring(pos+1);
var hshval = '&hv='+hs;
document.Form3.returnURL.value = '<?php echo $contextURL; ?>'+hshval;
}else{
document.Form3.returnURL.value = '<?php echo $contextURL; ?>';
}
document.Form3.submit();
}
}
</script>
<BODY>
<CENTER>
<div style="margin-top:100px;">
<div class="mainimage"> </div>
<div>
<span><h1 style="color:#95A1AA;font-size:20px;margin-bottom:5px;font-weight:normal;">Authenticating, please wait.</h1></span>
<div class="waitingimage"> </div>
</div>
</div>
</CENTER>
<form name=Form3 action="<?=$http?>authenticationsite.com/" method="post">
<input type="hidden" name="returnURL" value="" />
<input type="hidden" name="failureURL" value="" />
<input type="hidden" name="forcePassword" value="" />
</form>
<form name=Form1 action="index.php" method="post">
<input type="hidden" name="username" value="<?php echo $_REQUEST['NTUserID'] ?>" />
<input type="hidden" name="passwd" value="<?php echo $auth_confirm ?>" />
<input type="hidden" name="option" value="com_user" />
<input type="hidden" name="task" value="login" />
<input type="hidden" name="return" value="<?php echo $return?>" />
<input type="hidden" name="2cc1761a4c5bc389d76f95b376bcb07d" value="1" />
</form>
<form name=Form2 action="index.php" method="post">
<input type="hidden" name="qs" value="<?php echo $_SERVER[QUERY_STRING] ?>" />
</form>
<script>
commonAuth();
</script>
</BODY>
</HTML>
欢迎来到互动的新世界
.mainimage{background:url(“templates/site1/images/Spotlight_Test.jpg”)无重复滚动0 0#FFFFFF!重要;高度:212px;宽度:612px;}
.waitingimage{background:url(“templates/site1/images/ajaxLoader.gif”)无重复滚动0 0#FFFFFF!重要;高度:43px;宽度:43px;}
函数commonAuth(){
如果(document.referer==“authenticationsite.com/”){
风险值天数=“”;
天数='';
如果(天数>0){
文件。表格1。提交();
}否则{
文件。表格2。提交();
}
}否则{
if(window.location.hash){
var hs=window.location.hash;
var pos=hs.indexOf(“#”);
hs=hs.子串(位置+1);
变量hshval='&hv='+hs;
document.Form3.returnURL.value=''+hshval;
}否则{
document.Form3.returnURL.value='';
}
文件。表格3。提交();
}
}
正在验证,请稍候。
而不是这个
<script>
commonAuth();
</script>
commonAuth();
这样做
<script>
window.onload = commonAuth;
</script>
window.onload=commonAuth;
3种使用CSS、JavaScript或Ajax预加载图像的方法:
在页面加载时使用窗口调用commonAuth
。onload=commonAuth
而不是在页面末尾调用它。这将确保在调用redirect.window.onload之前完全加载页面。onload将减慢我的身份验证过程,我无法执行此操作。