Jump to content

Execute javascript code before page is loaded.


immunity

Recommended Posts

It has been fixed ! but still not my other topic :/hello i have a page and there is a cookie (username) that contains the username and passwordnow i want before my page is loaded if cookie is not null or "" to make a ajax request to serverand verify the user. If the username and password is correct the page would be loaded unlessit will window.location somewhere elsehow i can do this ? (i have ready the code to get the username / pass and verify the user) buti dont know where to put it so work before page will be loadedsome of code (tried something but didnt work)

<head><script src="clock.js"></script><script type="text/javascript">alert(getCookie('username'));if (getCookie('username')!=""){alert(getCookie('username');	mid= getCookie('username').indexOf(";");	name= getCookie('username').substring(0,mid);	pass= getCookie('username').substring(mid+1,getCookie('username').length -1);	url = "checklogin.php?p="+pass+"&a="+name;	http.open("GET",url,true);	http.onreadystatechange = function()

Link to comment
Share on other sites

i think i found my problem and that is if i add my code (if { ..} ) the page would incorrectly load :/if i remove the code the page will correctly load (alert the cookie)my code:

<html xmlns="http://www.w3.org/1999/xhtml"><head><script src="clock.js"></script><script type="text/javascript">account=getCookie('username');alert(account);if (account!=""){	alert(account);	mid= account.indexOf(";");	name= account.substring(0,mid);	pass= account.substring(mid+1,account.length -1);	url = "checklogin.php?p="+pass+"&a="+name;	http.open("GET",url,true);	http.onreadystatechange = function() 	{		if(http.readyState == 4 && http.status == 200) 			{				var results= http.responseText;				if (results ==0)				{					document.getElementById("membermenu").innerHTML="Kalos ir8ate<br>"+usr+"<br><strong><div id ='logout' onClick=logout(); >Logout</strong>";				}				else if (results==1)				{					window.location="admin.html";				}				else if (results.match("error"))				{					alert("Εισάγατε λάθος κωδικό/λογαριασμό");				}							}	}	http.send(null);	}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...