Opened 13 years ago
Closed 8 years ago
#5005 closed defect (fixed)
can't insert templated widget's DOM tree into an iframe
Reported by: | Owned by: | bill | |
---|---|---|---|
Priority: | high | Milestone: | 1.8 |
Component: | Dijit | Version: | 0.9 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description (last modified by )
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:
- Add srcNodeRef ivar to _Templated.
- 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.
- 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 [email protected]… 801-400-5111
Change History (8)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
Component: | General → Dijit |
---|---|
Milestone: | → 1.1 |
Owner: | changed from anonymous to bill |
comment:3 Changed 13 years ago by
Description: | modified (diff) |
---|---|
Reporter: | changed from guest to [email protected]… |
Just formatting the code segments above.
comment:4 Changed 13 years ago by
Summary: | Change _Templated so that it uses the ownerDocument of srcNodeRef to create the domNode → can'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:
- 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.
- 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 13 years ago by
Milestone: | 1.1 → 2.0 |
---|
comment:7 Changed 12 years ago by
Description: | modified (diff) |
---|---|
Milestone: | 1.3 → future |
comment:8 Changed 8 years ago by
Milestone: | future → 1.8 |
---|---|
Resolution: | → fixed |
Status: | new → closed |
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.
you can use dojo.withDoc and dojo.withGlobal to change dojo.doc