Reputation: 894
I'm creating an iframe and when I add it to the dom it does not load the url. I actually have to right click it and hit refresh...any reason for this to happen? I'm using this code on a CWE extension for Lync, that runs on an embedded browser but it's actually IE7.
Here's the code: (the url it's fine because hitting refresh load the right page so i did not included the to get the url)
var iframe = document.createElement('iframe');
iframe.id = "myframe";
iframe.height = "400";
iframe.width = "700";
iframe.style.border = "0";
iframe.scrolling = "no";
iframe.frameBorder = "0";
iframe.style.display = "block";
iframe.setAttribute("src", this.GetUrl(x));
main.appendChild(iframe);
Upvotes: 1
Views: 2556
Reputation: 48972
Try:
frame.src = this.GetUrl(x);
instead of:
iframe.setAttribute("src", this.GetUrl(x));
frame.src
is the property, while iframe.setAttribute("src", this.GetUrl(x));
sets the attribute.
To avoid inconsistencies and problems with old browsers, try appendChild
first so that the DOM is aware of its existence before setting the src
.
var iframe = document.createElement('iframe');
iframe.id = "myframe";
iframe.height = "400";
iframe.width = "700";
iframe.style.border = "0";
iframe.scrolling = "no";
iframe.frameBorder = "0";
iframe.style.display = "block";
// iframe.setAttribute("src", this.GetUrl(x));
main.appendChild(iframe);
frame.src = this.GetUrl(x);
Upvotes: 4