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
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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.