Ticket #5005 (new defect)

Opened 13 months ago

Last modified 2 days ago

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

Reported by: byersa@… Owned by: bill
Priority: normal Milestone: future
Component: Dijit Version: 0.9
Severity: normal Keywords:
Cc:

Description (last modified by bill) (diff)

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.

2. 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.

3. 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

Changed 13 months ago by liucougar

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

Changed 13 months ago by bill

  • owner changed from anonymous to bill
  • component changed from General to Dijit
  • milestone set to 1.1

Changed 12 months ago by bill

  • description modified (diff)
  • reporter changed from guest to byersa@automationgroups.com

Just formatting the code segments above.

Changed 12 months ago by bill

  • summary changed from Change _Templated so that it uses the ownerDocument of srcNodeRef to create the domNode to 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:

  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.

Changed 10 months ago by bill

  • milestone changed from 1.1 to 2.0

Changed 9 months ago by alex

  • milestone changed from 2.0 to 1.3

Milestone 2.0 deleted

Changed 2 days ago by bill

  • description modified (diff)
  • milestone changed from 1.3 to future
Note: See TracTickets for help on using tickets.