For an HTML Widget I’m using “Specified URL” and everything is fine except it could take a little time to load the URL data in the iFrame.
All several devices and browers I’ve tested on, the onload on the iFrame works great except for the iPad Mini and iPod Touch that I have.
Can anyone else get onload for an iFrame using the HTML Widget to work?
But without you supplying more information like what you are loading into the iframe, more specific detail on your setup and what is actually happening,what is not happening and what you expect to happen, I do not see how we can help you!.
Please help us help you by supplying more info. As to be honest my first thoughts on your post was to ignore it for lack of details.
Sorry, I was looking for an attachment button.
Didn’t realize you can just drag and drop your zip file.
If you notice in the hype3 document I put in comments to show how to see if the onload function ever gets called.
I tested with Safari, Firefox on a Mac, IE on a RT device but for some odd reason the onload function I set never gets called on my iPad Mini or iPod (newer iPod).
iOS 10.3 was just released and I installed it on my iPad Mini.
I am not sure why the original addEvent is not working but suspect it is to do with the way the addEvent is structured for iOS device and security.
I had to change something to get it to work.
Firstly I put the iframe in a Rectangle element. Which makes it simpler for use to not have to dive down children. <iframe id="HTMLWidgetId" frameborder="0" style="width:100%;height:100%;border:none" src="${resourcesFolderName}/index.html">…</iframe>
I then let the document find the iframe element. and change the add event to a type I know works.
var iFrameName = "HTMLWidgetId";
function func()
{
var frameDocument = document.getElementById("HTMLWidgetId").contentDocument || document.getElementById("HTMLWidgetId").contentWindow.document;
frameDocument.body.innerHTML = "<h1>testing</h1>";
console.log("here");
};
var iframe = document.getElementById("HTMLWidgetId");
var userAddEventListener = true;
if(true == userAddEventListener)
{
iframe.addEventListener('load', function(event) {
func()
});
}
else
{
iframe.onload = func();
}
For those that downloaded my hype3 document, I put in what Hans said and it’s working now.
Here’s what I updated the two lines as…
var frameDocument = hypeDocument.getElementById(iFrameName).querySelector(‘iframe’).contentDocument || hypeDocument.getElementById(iFrameName).querySelector(‘iframe’).contentWindow.document;
var iframe = hypeDocument.getElementById(iFrameName).querySelector(‘iframe’);
This is getting more of an opinion from you and Mark, but which is recommend to use
.addEventListener or .onload ?
I tired on all my devices as well as the iPad Mini and iPod and both work, but is there a preference?
Thanks, interesting reading and I might have figured out an issue I was having regarding addEventListener where you can have several events added as oppose to onload where only one event can be added. For this project I’m doing, I’ll stick with onload.
AddEventListeners are not an "IE thing" just that they support IE from versions 9 above. addEvent is an "IE thing".
Using "onclick" is fine but make sure that if you ever add to the code in the future that if you use the same method for the same element elsewhere in your code then you will overwrite the previous one.
Sorry, I meant to type attachEvent not addEvent but then I realized that Mark was referencing addEvent, not attachEvent.
I had attachEvent in my code sample but wasn’t using it because it wasn’t defined and now I know why it wasn’t defined because it’s an IE only thing, that was when I ran my sample with Safari on the Mac…
And yes, I’m using onload for that purpose where I don’t want more that one event assigned, at least for this project I’m working on, maybe other projects I’ll look at addEventListener.