Opened 12 years ago

Closed 7 years ago

#5005 closed defect (fixed)

can't insert templated widget's DOM tree into an iframe

Reported by: byersa@… Owned by: bill
Priority: high Milestone: 1.8
Component: Dijit Version: 0.9
Keywords: Cc:
Blocked By: Blocking:

Description (last modified by bill)

I am posting a bug that I first put on the forum list. It is about a half-dozen lines so I am going to describe the code rather than supply it because I don't have an CLA in place.

I have a situation in which I am trying to dynamically change the content of an iframe with code like:

var refNode = dojo.doc.createElement("div");
var newWidget = new cls({...}, refNode);
ifr.contentWindow.document.body.appendChild(newWidget.domNode);

This works in FF, but not IE. It complains about an "invalid argument". I finally figured out it was because the element that I am appending was not created by the iframe's document. I thought an answer to this would be to create refNode like this:

var refNode = iframe_contentwindow.document.createElement("div");
var newWidget = new cls({...}, refNode);

But in poking around in _Templated, I find that it uses "dojo.doc" to create the element it returns. I changed the code for it to see if it has a "this.srcNodeRef" and uses it's ownerDocument to create an element and that seems to work. I had to add "srcNodeRef" to _Templated and move the "tn" var inside the function so it gets recreated each time.

So the changes I made were:

  1. Add srcNodeRef ivar to _Templated.
  1. In dijit._Templated._createNodesFromText, I move the def of "tn" inside the function as it would never allow a change if the "tn" var persists.
  1. In dijit._Templated._createNodesFromText, I did a test on whether or not this.srcNodeRef exists and, if it does, set tn by creating a "div" from the this.srcnodeRef ownerDocument. There is also a line right below it that also uses "dojo.doc.createElement. I moved that line inside the conditional clauses, as well.

If you want my code, I will be glad to fill out a CLA.

Al Byers byersa@… 801-400-5111

Change History (8)

comment:1 Changed 12 years ago by liucougar

you can use dojo.withDoc and dojo.withGlobal to change dojo.doc

comment:2 Changed 12 years ago by bill

Component: GeneralDijit
Milestone: 1.1
Owner: changed from anonymous to bill

comment:3 Changed 12 years ago by bill

Description: modified (diff)
Reporter: changed from guest to byersa@…

Just formatting the code segments above.

comment:4 Changed 12 years ago by bill

Summary: Change _Templated so that it uses the ownerDocument of srcNodeRef to create the domNodecan't insert templated widget's DOM tree into an iframe

Thanks for the bug report and the patch. I have to think about it some. Two things initially concern me:

  1. For widgets without substition vars (like ${title}) we cache the DOM tree, and then clone it. Your suggested patch doesn't work for such a widget, if that widget appears in the main document and the iframe, or two different iframes, etc.
  2. slight performance hit from recreating dummy tn node all the time.

So, it seems like a slightly bigger issue to fix, and I'm not sure this is something we should be supporting anyway. It seems like a corner case to create widgets in the main document but insert them into an iframe.

comment:5 Changed 12 years ago by bill

Milestone: 1.12.0

comment:6 Changed 12 years ago by alex

Milestone: 2.01.3

Milestone 2.0 deleted

comment:7 Changed 11 years ago by bill

Description: modified (diff)
Milestone: 1.3future

comment:8 Changed 7 years ago by bill

Milestone: future1.8
Resolution: fixed
Status: newclosed

The particular issue described here was fixed in 1.8 w/the addition of the ownerDocument property of widgets. More complicated cases though don't work (ex: widgets depending on dijit/focus, etc.), and it's unclear if we'll add support for them or not.

Note: See TracTickets for help on using tickets.