?
Solved

Reloading Page without screen flickering, cursor changing

Posted on 2003-03-13
17
Medium Priority
?
1,446 Views
Last Modified: 2008-02-07
Hey

For my endwork, i need to reload a page which checks each second the mysql database for new records.
the problem is that the mouse cursor is always changing to wait mode and the screen is flickering.
Why checking every second? Because its very important for the stuff i need todo.
It must be kind of some 'status' which should change if the numbers of rows are increasing..

Is there any possible way to reload a page with JavaScript without flickering the screen neither a changing mouse cursor?
It must work in internet explorer, netscape and other browsers.. You have a solution?... Thanks in advance!!
0
Comment
Question by:xbone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
17 Comments
 
LVL 1

Expert Comment

by:bolesj
ID: 8127430

I have used this trick in the past and it seems to work well. Use a hidden Iframe embeded in your page and set the visablitiy = hidden. You can reload the iframe as many times as needed and the user will never see it. then use javascript to communicate changes from the Iframe into the parent window. It can get quite complicated depending on how much info you are trying to display but this has worked for me in the past.


0
 

Author Comment

by:xbone
ID: 8128262
can you please show some example code of it? it seems to work in internet explorer.. but in netscape/mozilla/konqueror the mouse cursor is still loading while reloading the iframe;.. what could i do please? help ;-) thanks in advance
0
 

Author Comment

by:xbone
ID: 8128298
can you please show some example code of it? it seems to work in internet explorer.. but in netscape/mozilla/konqueror the mouse cursor is still loading while reloading the iframe;.. what could i do please? help ;-) thanks in advance
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:xbone
ID: 8128310
i got a php page with the iframe in it:
check.php:

<?

echo "
        <html>
        <head>
        <script>
        function Hide()
        {
                iframe.style.visibility=\"hidden\";
        }
        </script>
        </head>
        <body>
        <iframe id=\"iframe\" name=\"iframe\" src=check2.php width=0 height=0 border=0>
        </iframe>
        </body>
        </html>
";

?>


and i got check2.php which includes the stuff which needs to be reloaded every second. but the problem is that the mouse cursor is always waiting/busy mode.. In netscape refresh == reload..

check2.php:
<?
session_start();
include('config.php');

echo "
        <html>
        <head>
        <script>
        function Reload()
        {
                window.location.reload(true);
        }
        function DoReloadPage()
        {
                clearTimeout();
                setTimeout('Reload()',1000);
        }
        </script>
        </head>
        <body onLoad=\"DoReloadPage()\">
";
if(! isset($counter))
{
        $counter=mysql_num_rows(mysql_query("select * from ip"));
        session_register("counter");
}
if($counter == mysql_num_rows(mysql_query("select * from ip")))
{
        echo "$counter";
}
else
{
        if($counter < mysql_num_rows(mysql_query("select * from ip")))
        {
                echo "<script>
                alert('New Record... Reload!');
                </script>";
                $counter=mysql_num_rows(mysql_query("select * from ip"));
                session_register("counter");
        }
}

echo "
</body>
</html>
";

?>


so can you help me find out why the mouse is still loading in netscape? Thanks ;-)

0
 

Author Comment

by:xbone
ID: 8128315
i got a php page with the iframe in it:
check.php:

<?

echo "
        <html>
        <head>
        <script>
        function Hide()
        {
                iframe.style.visibility=\"hidden\";
        }
        </script>
        </head>
        <body>
        <iframe id=\"iframe\" name=\"iframe\" src=check2.php width=0 height=0 border=0>
        </iframe>
        </body>
        </html>
";

?>


and i got check2.php which includes the stuff which needs to be reloaded every second. but the problem is that the mouse cursor is always waiting/busy mode.. In netscape refresh == reload..

check2.php:
<?
session_start();
include('config.php');

echo "
        <html>
        <head>
        <script>
        function Reload()
        {
                window.location.reload(true);
        }
        function DoReloadPage()
        {
                clearTimeout();
                setTimeout('Reload()',1000);
        }
        </script>
        </head>
        <body onLoad=\"DoReloadPage()\">
";
if(! isset($counter))
{
        $counter=mysql_num_rows(mysql_query("select * from ip"));
        session_register("counter");
}
if($counter == mysql_num_rows(mysql_query("select * from ip")))
{
        echo "$counter";
}
else
{
        if($counter < mysql_num_rows(mysql_query("select * from ip")))
        {
                echo "<script>
                alert('New Record... Reload!');
                </script>";
                $counter=mysql_num_rows(mysql_query("select * from ip"));
                session_register("counter");
        }
}

echo "
</body>
</html>
";

?>


so can you help me find out why the mouse is still loading in netscape? Thanks ;-)

0
 
LVL 1

Expert Comment

by:bolesj
ID: 8128331

Hmmm..... Not quite sure what to tell you. you can do it the dirty way. I dont reccomend this but:

Spawn a new browser window off the screen. Have it refresh every second and check for the new records and report changes back to the parent.

What are you using this for? That may help in the overall solution.....

0
 

Author Comment

by:xbone
ID: 8128463
thanks for the fast reply.

Well it would be good to launch a page somewhere off the screen, not visible and to check each second for mysql records. If the number of rows in the mysql database is greater then the previous counted (one second ago) then it must alert the parent screen that there has been a change or refresh the parent itself too.

So in short, the parent must print off every new number of rows in the database. So if after 5 seconds there are no new records, the parent may not refresh. If there are new records, the window off the screen must tell the parent to refresh because there are new records. Do you understand?... Just let the parent refresh when the child is getting a greater amount of rows in the mysql database.

Let me know. Thanks in advance.
0
 
LVL 1

Expert Comment

by:bolesj
ID: 8128808

i tottaly understand. But i was referning to more of an idea of what exactly this is used for. Is it used by administrators to view database changes or for the gen public.

If for public use: Most users (myself included) hate when windows are loaded off the screen unless i am told why beforehand. but from it looks like you need this parent and off screen child should work well.



as far as the child goes u can use the sessions but for just one trivial value on one page i wouldnt bother..just have your reload do somethign like this

<script>
window.setTimeout("location='child.php?numRows=<?MYSQLNumberRows?>'
</script>

then on the php side check to see if current number MYsqlRows == numRows from the query string. If it doesnt send the child window something like

if (quertString("numRows")!=MYSQL_num_rows($result))
{
echo " parent.refresh()";
}
else
{//nop - rows didnt change since last reload}

0
 

Author Comment

by:xbone
ID: 8129705
with this situation, my cursor is in wait mode and immediately back to default mode, when the child (popup) window is reloading each second (NOT refresh).

this happens only in netscape. Netscape seems to not understand that refresh != reload.

When you refresh in IE, the page refreshes and the mouse cursor is changing.. when you reload, the cursor is not changing in wait mode.

Is there any solution to keep the mouse in the default mode? Because the wait mode may not be used on my pages.. Got an idea for netscape/mozilla? ;-) thanks in advance
0
 
LVL 1

Expert Comment

by:bolesj
ID: 8129789


the parent should not show any behavior related to the child. the parent should never 'talk' to the child. And the child shoud never talk to the parent UNLess to tell parent.refresh()

setting <body style="{cursor:normal}"> might work but not sure

0
 

Author Comment

by:xbone
ID: 8130028
I does not work... Again, it works all fine in Internet Explorer, but in Netscape/Mozilla the cursor is changing every second back to wait mode on the parent screen!

This is the PHP page which will launch the POPUP:

<?
        echo "
        <html>
        <head>
        <script>
        function popup() {
                check=window.open(\"check2.php\", \"opener\", 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=1,height=1,left=0,top=0');
        }
        function Maximize()
        {
                popup();
                parent.window.moveTo(0,0);
                parent.window.resizeTo(screen.availWidth,screen.availHeight);
        }
        </SCRIPT>
        </head>
        ";

        echo "<body style=\"{cursor:normal}\" onLoad=\"Maximize()\">";
        echo "here buttons :-)";

        echo "<br><br><a href=javascript:parent.window.close();>Close</a>
        </body>";

?>



This is the popup itself, the code:

<?
session_start();
include('config.php');

echo "
        <html>
        <head>
        <script>
        function Reload()
        {
                window.location.reload(true);
        }
        function DoReloadPage()
        {
                clearTimeout();
                setTimeout('Reload()',1000);
        }
        </script>
        </head>
        <body onLoad=\"DoReloadPage()\">
<base target=\"_self\">
";
if(! isset($counter))
{
        $counter=mysql_num_rows(mysql_query("select * from ip"));
        session_register("counter");
}
if($counter != mysql_num_rows(mysql_query("select * from ip")))
{
        if($counter < mysql_num_rows(mysql_query("select * from ip")))
        {
                echo "<script>
                parent.opener.location.reload(true);
                </script>";
                $counter=mysql_num_rows(mysql_query("select * from ip"));
                session_register("counter");
        }
}

echo "
</body>
</html>
";

?>


As you can see, i try to reload the page every second... its in a popup.. so the cursor will change every second, no problem i minimize it  and it works fine on the parent screen in internet explorer, try the same thing in netscape or mozilla, your cursor is always loading every second.. is that a bug or so? How to solve the problem ? Really, IE works fine with it, but netsheep must also work with it.. any CSS or other solution? ;)
0
 
LVL 1

Expert Comment

by:bolesj
ID: 8130372

have you thought about an applet?
0
 

Author Comment

by:xbone
ID: 8130436
what kind of applet should i make?... i don 't know how to make it. Can you make a little example maybe? ;-) I think there are lots of people who have this problem like me and want a solution.. let me know ;-) thanks in advance
0
 
LVL 1

Accepted Solution

by:
bolesj earned 150 total points
ID: 8137621
Well the entire problem you are facing is because you want real-time stats on an HTML page. HTTP Client/server architectures with server side scripting are not going to provide you with this type of functionality. There are ways around it and tricks to come close but you will have to make a couple sacrifices. Such as short delays (1 second in your case) and UI things such as the cursor issue.

With an applet you have a program embedded in your web page that access the database sever from the client pc. I have written a few applets in my time but do not normally like them. You may also look into Flash. It is also an embedded object it can perform some tasks that may help you.

There is no 5-minute solution to what you want to do (that i have seen).  As far as the applet, google 'java applet tutorials' and go from there. As far as flash: see if there is a way that you can load the status page into a flash text box and then go from there.


Btw: again what are you trying to do this?
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10130709
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: bolesj {http:#8137621}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0
 

Expert Comment

by:SimianStar
ID: 10459232
if you only need a boolean result.. why dont you set an image such that

<img src="yourphpcode.php" id=imgMySQL style="visibility: hidden;display: none;">

then in your javascript code you should write your timeout to set a new src for the img.
well the same source.

     obj = getobject('imgMySQL');   <---- or whatever your function to return the right object handle is...

     obj.src = "yourphpcode.php"

in your php code for the image you simply need to check the database.
if there has been a new record then return a broken image .. ie. dont send header info for the image.
or if there has been no record,  return just a workable image.

OR.. return an image of a certain width/length.. say 100px for a new record. 50 for no new record

then in your javascript timeout.. you can include a test to see what the image contains.
 you could check the image properties for the size / if its a broken img.
then act on the results.

ive only just thought of this as a solution to the same problem im having.
i did a quick test and it doesnt seem to change the mouse. or make the annoying click occur.
I could be wrong.
give it a go. Im going to
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question