Jump to content

Using Ajax to flash a message in browser


ReMuSoMeGa

Recommended Posts

I need a script, that will let me flash a message on the viewer's browser.

I need to be able to set how long the text will stay there, like even less than a second.

I need it to be displayed in a random place on the screen.

 

Im farily new to ajax, but I have experience with it. Any help will be appreciated,

 

Thanks

-Remus

Link to comment
https://forums.phpfreaks.com/topic/69052-using-ajax-to-flash-a-message-in-browser/
Share on other sites

you need to trigger a javascript function using an event like onload(if you want the message to appear when the user first enters the page). Then a <div></div> tag containing the message should be rendered by a server-side page(php/asp) that will be opened by the javascript xmlHttp object. The random position can be achieved in various ways depending on each browser.

if this sounds a little bit tricky take a look at ajax right here: http://w3schools.com/ajax/default.asp

ReMuSoMeGa,

 

You might want to look at the overLib Javascript solution...

 

http://www.bosrup.com/web/overlib/?Command_Reference :: Specifically the the TIMEOUT parm and the FIXX / FIXY parms... The location parms could be generated via javascript or server-side (PHP / ASP) functions before the call to overLib is built.  See my post earlier today pertaining to overLib here:  http://www.phpfreaks.com/forums/index.php/topic,157902.0.html

 

Scot L. Diddle, Richmond VA

 

 

I left the city for a few days and now i'm able to read the post. I worked a quick code that makes a pop-up appear random between 0px and 300 and dissappear after 1 sec. Refresh the page to see different positions of the div. Hope it helps you!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style>
.Div {
position:absolute;
width:150px;
height:30px;
background-color:#666666;
display:none;
}
</style>

</head>

<body onload="Start();">
<div id="myDiv" class="Div">Some text goes here</div>
<script language="javascript">
var t;
var k=0;
var n=Math.floor(Math.random()*300);
var obj = document.all? document.all.myDiv : document.getElementById("myDiv");
function makeTo() {
	k++;
	obj.style.left=n+"px";
	obj.style.top=n+"px";
	obj.style.display="block";
	if(k>10) {
		obj.style.display="none";
		clearInterval(t);
	}	
}
function Start() {
	t=setInterval('makeTo();',100);
}
</script>
</body>
</html>

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.