It's much saner to add the postMessage in the global JavaScript and the event listener in the JavaScript within your HTML file. However, most of those are probably not things that you need, so if you were to do it the way you wrote and try to post a message from the iframe to the parent frame by adding an event listener in the custom JavaScript and the postMessage in the JavaScript within an iframe, you would want to make sure that the events bubble back to Canvas' handler so you didn't break other things. Some of those require a token that is sent during the LTI launch, but others could be used by JavaScript acting within an iFrame. It allows you to request a full window launch, toggle the course navigation menu, hide the right side wrapper, resize the iframe, get the window size, show the module navigation, scroll to the top of the page, show an alert for screen readers, show an alert using the Canvas system, enable scroll events, and a couple of others. My confusion was why you would be using postMessage in the first place if you didn't know about the eventListener so that you could use it?Ĭanvas has an eventListener for messages coming from LTIs. Y ou can use JavaScript’s contentWindow property to force iFrame to automatically adjust its height based on the content it contains, so that no vertical scroll bar appears. My solution was based off of what you had written that you already had working. But with an external LTI, Canvas can pass all of the information that you need to pass to the external tool and then it can act on it and deliver the content.Īn LTI is not the easiest way (easiest is different from best). Iframes let you build user experiences into embeddable ‘cross-domain components’, which let users interact with other sites without being redirected. I think the best method is probably to use an external tool or LTI, but there are cases where that isn't going to work for people. Your iFrame HTML would have to have its own JavaScript that would have an eventListener for the "message" event type to listen for the message sent by the postMessage sent from the parent frame and then act on it.Īs for the best method, I would not go that far. The code that you inject into the custom JavaScript would have to have the postMessage. The iFrame would not have access to the API to make the call. Perhaps they would be if you're storing the HTML in the files section of Canvas rather than on an external server (I would discourage that approach), HTML5 introduces the sandbox attribute on the iframe that, if empty, disables JavaScript loading and execution. inside our CMS without CSS or JavaScript conflicts. IFrames are sandboxed and don't have access to APIs. Pym.js embeds and resizes an iframe responsively (width and height) within its parent container. I don't even think what you wrote is possible.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |