Search code examples
iframesproutcore

How do you add an iframe to a view in sproutcore?


I've got some legacy code to work with and I have no experience with Sprout Core. Searching for the answer has proven inconclusive.

Basically, I need to just an add an iframe to an already existing view, and be able to set the src URL.


Solution

  • While you can render a fixed iframe very easily using the render function, there is also a SproutCore view, SC.WebView, that does this for you in the :desktop framework. You should use SC.WebView if you expect the src to change or if you want to resize the iframe to match the size of its contents.

    For example,

    myWebView: SC.WebView.extend({
      layout: { left: 10, right: 10, top: 10, bottom: 10, border: 1 },
      shouldAutoResize: true, // when the iframe loads, resize it to fit the size of its content
      valueBinding: SC.Binding.oneWay('MyApp.currentUrl') // bind the 'src' of the iframe
    })