| |
Author |
Post |
|
#1 Tue Nov 20, 2012 10:48 pm
|
Member
Registered: Apr 2009
Posts: 52
Location: Everett, WA
|
I've been attempting to migrate some of my older code that worked with a previous version of FB that was something like this: var myDoc = fb.lastChild.fbParent.fbContent.contentWindow.document; To something more like this: var myDoc = fb.getInstance( 'name' ).fbContent.contentWindow.document; Is there any way to set a FB's instanceName via JavaScript or do I have to have called fb.start() and assigned it in its options? I can go back and change all the code that calls this particular interface so that it's specified but was wondering if maybe I could just set it from within the iframe and then reference it? And of course if there's some better way of accomplishing this task, I'm all ears. -b
|
|
#2 Wed Nov 21, 2012 2:17 am
|
Administrator
Registered: Aug 2008
Posts: 3382
|
Well, yes you can, but...
The javascript code would need to find the floatbox instance first before doing a backdoor assignment of instanceName to it. The whole purpose of assigning a name is to make referencing a particular box easy when multiple boxes are opened. But if you can back-door the name with javascript, you already have a reference to the instance, and so there's not really any reason to give it a name at that point.
If you must, you can set myFloatboxInstanceReference.name = 'myInstanceName'
I don't know if it's a fit in your circumstances, but the Floatbox API has a fb.ownerInstance( node/id ) function that returns an instance reference. If you have an element with a unique id on it inside the floatbox of interest, a call of fb.ownerInstance('myUniqueId') should return a reference to the instance that that element resides in.
|
|
#3 Wed Nov 21, 2012 6:47 am
|
Member
Registered: Apr 2009
Posts: 52
Location: Everett, WA
|
Gotcha, that logic makes sense to me. I have a button on the page with the following code: <input id="saveChangesButton1" type="button" class="silverButton" value="Save Changes" style="float:right;margin-right:20px;margin-top:20px;" onclick="fb.ownerInstance('saveChangesButton1').end();"> When clicked, this should close the floatbox that this button resides in, yes? Testing it though, the JavaScript console errors out with: Uncaught TypeError: Cannot call method 'end' of null There are two Floatboxes (iframe content) open and the parent page and two Floatbox instances are all loading the same 550 script/css. Does it make any difference that the first Floatbox instance iframe that spawns the 2nd has its Floatbox JS src with the ?framed variable tacked on? I wouldn't think that would matter as the spawning of the 2nd Floatbox instance is accomplished using a parent.fb.start() call but thought I'd ask. -b
|
|
#4 Wed Nov 21, 2012 7:03 am
|
Administrator
Registered: Aug 2008
Posts: 3382
|
The ?framed setting may be getting in your way. It creates an isolated instance of Floatbox that does not integrate with the base page instance. When you pass an id to the ownerInstance function, the function calls on the services of fb.$() to go find that node. fb.$() won't go looking across ?framed boundaries. (Nor can it go looking inside cross-domain iframes.) Since you're making the end() call from an onclick action, you should be able to use javascript's "this" reference to refer to the clicked element. Try onclick="fb.ownerInstance(this).end();". And please report back with tales of success.
|
|
#5 Wed Nov 21, 2012 7:59 pm
|
Member
Registered: Apr 2009
Posts: 52
Location: Everett, WA
|
Yup, the ?framed is the culprit. I put together this test to illustrate: http://proto.cristina.org/fb_test.htmAs you can see, if the iframed Floatbox is loaded with ?framed, fb.ownerInstance() and fb.getInstance() always produce null results. I did notice in my testing though that I can still access an instance using top.getInstance(). -b
|