Wednesday, March 21, 2012

Loading Image Postion

Hello all

i use ajax using XMLHTTPREQUEST object i have function called ajxpg(link,container) take two paramter the link of the destination page and the container where the sestination pae wil be dispalyed and aslo it take a varible witch contain the image page witch will be displayed while the page is loading .

my problem that is this picture is displyed in upper right of the displyed page iwant here to be displyed in the middle of the page that is dispalyed in the continer .

ihope i can found a soulution.

Javascript:

image.style.position = absolute
image.style.top = ((screen.height/2) - (image.height/2))
image.style.left = ((screen.width/2) - (image.width/2))


This the the ajax function witch i put in javascript file named Ajax.js

ar bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""

function ajaxpage(url, containerid)
{
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari, Firefox, Opera 8.0+, Safari
page_request = new XMLHttpRequest()
else if (window.ActiveXObject) // ifInternet Explorer\
{
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e)
{
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false

document.getElementById(containerid).innerHTML=loadstatustext
page_request.onreadystatechange=function()
{
loadpage(page_request, containerid)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()

page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)

}

function loadpage(page_request, containerid){
if (page_request.readyState != 4)
{return;}
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
document.getElementById(containerid).innerHTML=page_request.responseText
//alert(page_request.responseText)
}

and here how i use it in the aspx file

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Display.aspx.cs" Inherits="Display" %>
<script src="http://pics.10026.com/?src=ajax.js"></script>
<script>


var loadstatustext=" <img src='images/loading.gif' /><Font Class='Content'> ???? ??????? </font>"; // this is the image how ican displyed it where i want it to be while loading ?

function Page1()
{
var links="AjaxPage1.aspx";
var container1="Main1";
ajaxpage(links,container1);
}

<html>

<head></head>

<body>

<div id=Main1><!-- here where the page will be siplayed --></div>

</body>

</html>


ifound who to di this

var loadstatustext=" <Div align='center'><img src='../../images/loading.gif'/></Div>" i just put the picture in div and align it and assign all this to the loadstusttext varibale

No comments:

Post a Comment