I'm trying to use an iframe's body as a Region in Backbone Marionette. Marionette uses standart jquery selectors to define which element is the region, like this:
App.addRegions( { main: "#main-region" } );
I want my region to be the body of an iframe, which normally I would find like so:
$('iframe').contents().find('body');
When trying to put above as the region, like this:
App.addRegions( { main: $('iframe').contents().find('body') } );
The following error is thrown:
Uncaught Error: Syntax error, unrecognized expression: iframe.contents() body
Sizzle.error jquery.js?body=1:4681
tokenize jquery.js?body=1:4742
select jquery.js?body=1:5114
I tried to put the selector in directly:
App.addRegions( { main: "iframe.contents() body" } );
But it's giving me the exact same error.
EDIT:
Also tried to create a psuedo-selector for it:
$.expr[":"].contents = $.expr.createPseudo(function(selector) {
return function(el) {
var $el;
$el = $(el);
console.log($el.contents().find(selector));
return $($el.contents().find(selector));
};
});
// Usage: $('iframe:contents body');
Which does log the iframe's body in the function itself:
[body, prevObject: jQuery.fn.jQuery.init[1], context: iframe, selector: ".contents() body", constructor: function, init: function…]
But eventually returns the iframe element somehow:
[iframe, prevObject: jQuery.fn.jQuery.init[1], context: document, selector: "iframe:contents(body)", constructor: function, init: function…]
So, what I need, is a selector that is able to get the iframe's body or something else that could work with Marionette.
Is there a way to get this done?
$('iframe body')
). – Tim Baasiframe.contents() body
and throws the error stated above. – Tim Baas