Topic: Making xajax bookmarkable - a little advice needed

Hey everyone,

When I'm not working on HTTP Streaming I'm working on getting the 'back' button and bookmarks working in xajax.

And I have!.... at least in everything except Internet Explorer which can't pick up on the fact that anyone has pressed the 'back' button, unless I use an IFrame - an IE specific solution.

What I'm now having problems with is that since xajax is running in between the <head> tags, the <body> tags havn't been created yet, and so xajax can't add the iframe to the body (otherwise it makes the whole page stuff up)

So I'm asking for your suggestions in how I can add something to the document.body when it doesn't exist yet.  Has anyone else had these problems?

Cheers,
--BigBrownChunx

2 (edited by Craig 2006-03-07 11:56:28 AM)

Re: Making xajax bookmarkable - a little advice needed

body's onload to call a function?

Re: Making xajax bookmarkable - a little advice needed

I would second craigs idea.
Another option is to do a little delay before inserting the iframe, so that while the javascript still waits the rest of the page is being loaded.
I don't know if this works (maybe the JS stops the page from being loaded), but you could try. Drawback is, that if the user presses the back-button during the waiting period this won't work as you expect.

So try craigs idea first, then try mine.

Creativebyte

P.S.: Thanks for all the work you put into xajax. :-)

Re: Making xajax bookmarkable - a little advice needed

I assume that the bookmarking starts getting interesting when or after initiating the first xajax request.
So, maybe you could add in internal pre- or post-action to create the iframe on the very first xajax request.

Re: Making xajax bookmarkable - a little advice needed

Craig wrote:

body's onload to call a function?

The body doesn't exist yet to add to smile  Makes it tricky.

Creativebyte wrote:

Another option is to do a little delay before inserting the iframe, so that while the javascript still waits the rest of the page is being loaded.

Not sure how long to have the timeout, could vary depending on the speed of the connection to the server.

ralf wrote:

create the iframe on the very first xajax request.

I've thought about it, and dreaded it.  It'll need some code changes - but I guess I had to expect that.


I'll try all three and tell you how it goes.  More suggestions are welcome in the meantime.

6 (edited by Craig 2006-03-08 9:35:29 AM)

Re: Making xajax bookmarkable - a little advice needed

What about this in your <head>'s javascript?

window.onload = function(){
  JScriptFunc('param1');
}

Re: Making xajax bookmarkable - a little advice needed

Was thinking about the window.onload idea.  But if it's already in use, I should append it somehow?

Havn't tried the other ideas yet either.... just about to

Re: Making xajax bookmarkable - a little advice needed

OK, I got it working.  It doesn't do it until the server tells the client what the name of the page is.
Except in IE sometimes it wants to load the page up twice if it gets the timing wrong. So occasionally you have to press the 'back' button twice to get back to the previous page. *sigh*

Almost there, ladies and gentlemen.

Re: Making xajax bookmarkable - a little advice needed

Simple fix after all, just had some things around the wrong way.

So its all done.....
who dare try the yukky looking code?
<scary ghost noises>wooooo!</scary ghost noises>

Re: Making xajax bookmarkable - a little advice needed

If anyone wants to try it out heres a zip file with the updated xajax files, and a sample PHP file (without HTML code) as an example of how to do it.

11 (edited by mstar 2006-03-10 4:40:11 PM)

Re: Making xajax bookmarkable - a little advice needed

I tried your source but my scripts doesn't work both IE and FF.

FF says: xajax_process_browse_url is not defined.

...
function process_browse_url($url)
{
        $objResponse = new xajaxResponse();
        $objResponse->addWaypoint('asd');
        if (!check_auth()) {
                $objResponse->addRedirect("./");
                return $objResponse->getXML();
        }
        do_include($objResponse,"",$url);
        return $objResponse->getXML();
}



$xajax = new xajax();
//$xajax->debugOn();
$xajax->statusMessagesOn();
$xajax->errorHandlerOn();
//$xajax->setLogFile("../xajax/xajax_log/errors.log");

//$xajax->registerFunction("process_form");
$xajax->registerWaypointFunction("process_form");
//$xajax->registerFunction("process_browse_url");
$xajax->registerWaypointFunction("process_browse_url");

$xajax->processRequests();

Maybe i missed something?

As i understood with you new beta must work "Back" and "Forward" buttons? That would be great.

But what should i do to achive such a functionality?
And i don't understand this piece of your code:

if (function_exists('page_load'))
            {
                $loadedPage = page_load();
                if (is_a($loadedPage,"xajaxResponse"))
                    $loadedPage = $loadedPage->getXML();
                $objResponse->loadXML($loadedPage);
            }
            //***This is the new bit: add a waypoint***
            $objResponse->addWaypoint($newTabName);

BBC, maybe you should place some piece of doc how to use your code.

Re: Making xajax bookmarkable - a little advice needed

Oh yeah.  It might need the $xajax->registerFunction() too (but shouldn't)

There's comments in the code saying what that function does.  The line above the "if (function_exists...." part says (or should say) that if theres a xajax PHP function page_load() in the included PHP file then to call that function and show the changes that that function uses.

The important part about the whole back button/bookmarking is setting the points that you want people to go back to or to bookmark.  And that's done with the addWaypoint() method, pass it a unique value for that content that your registeredWaypointFunction knows what to do with (kind of like an internal reference), and then you've got a point to go back to.

But yes, it needs more documentation :s

13 (edited by mstar 2006-03-13 9:24:45 AM)

Re: Making xajax bookmarkable - a little advice needed

Yes.
Now it works: adds #$sWaypointName to url of script. And when i click "Back" it change the url to #$previousWaypointName, but the previous content isn't changed.

So, waiting for some info how the "$sWaypointName" should be parsed and where.

I didn't find how to figure it out.

Thanks for your real help in improving xajax.

Re: Making xajax bookmarkable - a little advice needed

The previous content should change when your registeredWaypointHandler is called.  is it called at all?

hmm... i think it needs more planning (and definatly more documentation)

Re: Making xajax bookmarkable - a little advice needed

BigBrownChunx wrote:

The previous content should change when your registeredWaypointHandler is called.

I think it should change too. But it doesn't.

BigBrownChunx wrote:

is it called at all?

Yes, it's called.

Waiting for doc.

Thanks for help.

Re: Making xajax bookmarkable - a little advice needed

so your function is called when the back button is pressed, but your function doesn't update the page to reflect the previous page that was reached?

doco still coming, i've been on a break smile

Re: Making xajax bookmarkable - a little advice needed

Dear BigBrownChunx!

This inprovement is really fantastic! Ive got it to work... but I needed to play a bit with it.. sometimes I ran into funny page reload loops...

But now it works great with FF and Opera (not tryed in IE)! Please improve the code a bit and insert it in the offical release!! This would be a really important and useable feature for the whole community.

Thank you!!
Andras Nemeseri

Re: Making xajax bookmarkable - a little advice needed

thanks, nemesa.  i'm glad it works for somebody smile

once its bug-free and working (and well-documented) then i'll put it in smile

what code improvements would you like to see

Re: Making xajax bookmarkable - a little advice needed

BigBrownChunx wrote:

so your function is called when the back button is pressed, but your function doesn't update the page to reflect the previous page that was reached?

My xajax_function isn't called.

Here are what i'm getting when i click "Back" button:

http://dalmatech.open.net.ua/mstar/tmp/debug_.gif

But i suppose :xajax_process_browse_url" function is to be called.

I must do something wrong, or missed something important. Here is my source:

//#################################################################################
function process_browse_url($url)
{
        $objResponse = new xajaxResponse();
        if (!check_auth()) {
                $objResponse->addRedirect("./?auth=bad");
                return $objResponse->getXML();
        }
        do_include($objResponse,"",$url);

        //$objResponse->addWaypoint($action);
        $objResponse->addWaypoint(rand());

        return $objResponse->getXML();
}
//#################################################################################

$xajax = new xajax();
//$xajax->debugOn();
$xajax->statusMessagesOn();
$xajax->errorHandlerOn();

$xajax->registerWaypointFunction("process_form");
$xajax->registerFunction("process_form");
$xajax->registerWaypointFunction("process_browse_url");
$xajax->registerFunction("process_browse_url");


$xajax->processRequests();

$main=str_replace("::xajax_javascript::", $xajax->getJavascript('../xajax') ,$main);

Re: Making xajax bookmarkable - a little advice needed

That message you're getting is normal.  It's just telling the client that it has gone 'back' to the correct page. but it's missing any information to say what the page is doing.

$objResponse->addWaypoint(rand());

any waypoint you set with addWaypoint, is what's passed back to that function when you press the 'back' button.
so

function process_browse_url($url)

will be given the value of the random number in the $url variable, which probably isn't much help to you here.

how about

$objResponse->addWaypoint($url);

instead?

21 (edited by mstar 2006-03-20 5:21:39 PM)

Re: Making xajax bookmarkable - a little advice needed

I found the problem - i have the urls like "?action=config&click_from_menu=1" and i need to do

$url=urldecode($url);

And now i have 1 per second xajax request with this url (non stopping). It looks like $objResponse->addWaypoint($url); adds one more xajax request which adds a request and so on. Because when i comment this function requests stop. (for IE 6.0)

I tested a bit in FF 1.5: and it works, not ideal, but it works. As for my Opera 8.53: looks like there are no requests at all when clicking "Back" button.

And one more thing i noticed: what should i do if i need to have severall wayPointParameters like

addWaypoint(arg1,arg2,arg_array,other_type_arg)

Re: Making xajax bookmarkable - a little advice needed

Yeah. a little bug on IE that occasionally it keeps switching between previous and current pages.  just because it's dumb and i have to resort to iframes :s

mstar wrote:

I tested a bit in FF 1.5: and it works, not ideal, but it works.

glad to hear it worked.  how is it not ideal?

and it doesn't work with opera 8? i'll have to reinstall it and give it a try - works in opera 9.

as for several waypoints there are limitations with using values after the #
you can use
$objResponse->addWaypoint(arg1.'&'.arg2)
then you'll have to break it up with

function process_browse_url($url)
$parts = split('&',$url);

when it comes in


but arrays and objects, no.  remember it's all being stored in the url of the page as it changes.

Re: Making xajax bookmarkable - a little advice needed

BigBrownChunx wrote:

how is it not ideal?

Only one step back is available for me. Other's (second, third) - urls and content aare not changed.

BigBrownChunx wrote:

for several waypoints there are limitations with using values after the #

Aha. I understand the limitations.

Thanks for great work.

Re: Making xajax bookmarkable - a little advice needed

It may be possible to pass values easily enough after the #. Instead of passing the default & why not pass a ","... yes thats right a ,. This way you could take in the values after the # and explode them into an array. Of course you would need to know what each value means in the array position but this is not that difficult for smaller apps. For larger ones that generate big argument URL's well then there could be a problem.

Also I have been doing a bit more digging. This article looks very interesting, but I am having a hell of a time getting my head around it and XAJAX working together. BigBrownChunx have you got any more ideas on this?

Thanks for all the code BTW, I am hoping to test it later today.

Re: Making xajax bookmarkable - a little advice needed

Interesting article, but it only fixes the back button.  The code above works for both the back button and bookmarking, however it messes up a little in internet explorer due to timing issues.

I'm working towards having a back button/bookmarking plugin for the next version of xajax, but i'm concentrating on getting the next version functioning first.

ajmckee wrote:

This way you could take in the values after the # and explode them into an array.

yep, we were talking about that in my last post smile

BigBrownChunx wrote:
$parts = split('&',$url);