loadPageOnClose Help

Page: 1

Author Post
wcjoker
Guest
Hello,

I have a floatbox popup, and a button to delete an item. When the user clicks the button another floatbox pops up and confirms the delete. After the user clicks yes the floatbox displays in the same pop up a confirmed delete. When the user clicks the close button on the popup I want the parent floatbox popup to refresh. There are no iframes or anything on the parent pop up, just some menus(javascript) and data being displayed. For some reason the loadPageOnClose is not working.

I have not found any other posts that don't talk about my exact situation.

Any help would be great, thanks in advance.

Mark 8)
Administrator
Registered: Aug 2008
Posts: 3382
loadPageOnClose won't do it for you. loadPageOnClose happens on your main page (not in a floatbox) when the last floatbox closes.

Although you say there are no iframes involved, I suspect that your floatbox content is loaded as iframes. This is the case if your content is a standalone page. Another likely case is that your content may be ajax, or possibly inline from a hidden div. To avoid guessing and the associated risk of answering the wrong question, could you please tell me a little bit more about the type and nature of the content in your two boxes.

Thanks...
wcjoker
Guest
Hello,

On our main page we have a link:


<a href="service_view_configuration.php" class="floatbox" rev="color:blue width:95% height:95% padding:0 infoPos:tc controlPos:tr caption:`` loadPageOnClose=self">Service View Config</a>

This floatbox works great, when I close it the main page refreshes, I understand why this works now :)

On the floatbox from the main page I have a link:

<a href='javascript:fb.loadAnchor("delete_view.php?prompt=true&label=$_GET[label]&uvid=$_GET[uvid]","color:blue width:350px height:200px padding:0 infoPos:tc controlPos:tr caption:`` loadPageOnClose=service_view_configuration.php");'>Delete</a>

this floatbox works great, just no refresh on close, and I understand why now.

The content that loads the first(parent) floatbox loads some data from an oracle database using a custom class, no ajax just PHP and HTML.

The data is displayed in DIV tags with CSS from an external style sheet.

Once the user clicks the delete button it loads a simple html form to confirm the delete. then when the user clicks the go button it posts back to the same delete_view.php page and checks for confirm and does it's thing. that all works great. I want the parent floatbox to refresh when the confirm floatbox closes.

I hope that's enough information to help you help me :)

Thanks in advance,

Mark
Administrator
Registered: Aug 2008
Posts: 3382
Good description. Thanks.

I notice you're using the deprecated function fb.loadAnchor which has been replaced by the more appropriately named fb.start. loadAnchor still works, and will keep doing so, but I just want to give a heads up that the solutions offered here require v3.53 or later.

Also, I would like to refer you to this thread. It's rather long and doesn't directly address your use case, but it's closely related. It's updating content on the main page based on an action from a form. I'm pointing it out because that is an alternate approach you could take. Instead of refreshing the entire contents of your first floatbox, you could dynamically update a portion of that content in the manner shown in that thread. Where it addresses an element on the main page, you could address an element on your floatboxed page.

It's pretty simple to refresh the content in your first floatbox, but a challenge is getting the timing right. If you refresh it as soon as the user clicks the button, the backend db processing will likely not have completed and the refreshed page won't reflect the changes. So we need to make the submission from the second box, wait for that submission to complete, and then refresh the box. Two ways to do that: post via ajax, or a form submission action. I think ajax is the cleanest.

First, let's build the function that will refresh your first floatbox. The fb variable points to that box, fbContent is the container element for your content in that box, and in the case of loading a php page, fbContent is an iframe. To refresh it, we merely need to update its src attribute. We need to add a random querystring entry to make sure it changes and to make sure the page doesn't reload from cache.
function refreshBox1() {
var src = parent.fb.fbContent && parent.fb.fbContent.src;
if (src) parent.fb.fbContent.src = src + &#039;&rand=&#039; + Math.random();
}
Notes:
- If src doesn't initially have a querystring, replace the '&' char with '?'.
- We're using 'parent' here because floatbox.js might not be included on your second form so the fb var might not be defined in that window.

Now it's just a matter of submitting your mini confirm form and executing the refresh code in response.

Ajax:
Bundle up any post values you need to submit into a string, make an ajax post, and refresh box1 in the callback to that ajax post.
function values() {
var data = &#039;val1=&#039; + encodeURIComponent(&#039;someString&#039;);
data += &#039;&val2=&#039; + encodeURIComponent(&#039;anotherString&#039;);
return data;
}
function onComplete() {
refreshBox1();
parent.fb.lastChild.end();
}
<button
onclick="parent.fb.ajax({ url:&#039;targetPage.php&#039;, postData:values(), callback:onComplete });"
>confirm</button>
Notes:
- If you want to use a GET rather than a POST, omit the postData entry and put that string on the url's querystring.
- If you don't need to submit any data values, just leave both postData and the querystring out of the picture.
-Make sure targetPage.php returns something (maybe just an empty div) so the ajax call will complete and fire its callback.
-Your backend can know that this is an ajax request by checking that the request header 'X-Requested-With' is set to 'XMLHttpRequest'.

Submit:
You can do a form submit instead of the ajax call if you prefer. In this case, the returned page from the submit action should contain the inline javascript that does what we did above in the ajax callback. That is, the action response should refresh box 1 and then close the top box.

A lot of words, but it's really quite straight-forward. It takes a lot more words and time to describe the process than to implement it.

Cheers...
wcjoker
Guest
Hi,

Thank you so much for the help, your response was perfect. It now works as I hoped it would :)

Have a great day,

Mark
Member
Registered: May 2013
Posts: 1
I try to understand but am not much of a programmer and want to try to use Floatbox. The main thing I want to accomplish is once a Floatbox window is opened, then either accidentally or on purpose, the window is closed, I want to load another page, most usually the same page that called the Floatbox window, hopefully to be refreshed. Then the user can see the changes made to databses when he was inside the Floatbox.

I searched her and also looked at the documentation but I'm still confused and would very much like to see a basic example of how to set up a page and Floatbox to do this. Do I use loadPageOnClose and if so, exactly how in some example please.

If loadPageOnClose is not the correct option, then please direct me to the correct one and give basic example how this is done. I read the docs about "Set loadPageOnClose to the string 'self' to refresh the host page on exit." but this is the part that's confusing so would very much like to see a working example code.

Also, is there an option to keep the window from closing when clicking outside the box, close only when clicking the X to exit?
« Last edit by GeorgeKing on Sat May 11, 2013 5:05 am. »
Administrator
Registered: Aug 2008
Posts: 3382
Don't overlook what should be the first place to to for information about using Floatbox options: the Options Reference, and also the Instructions.

It is the loadPageOnClose option that you are looking for. To refresh the current base page, set loadPageOnClose to self. To navigate to another page, set loadPageOnClose to the URL of that other page.

For example:
<a href="image1.jpg" class="floatbox" data-fb-options="loadPageOnClose:self"> 1 </a>
<a href="page49.php" class="floatbox" data-fb-options="loadPageOnClose:`http://yahoo.com/`"> 2 </a>


As for closing the box, please see the outsideClickCloses entry in the Options Reference.

Page: 1