You are doing some really random things here.
var iframe='<iframe class="adframe" id="111" name="widget" src="#" width="300" height="250" marginheight="0" marginwidth="0" frameborder="no" scrolling="no"></iframe>';
You now have a string called "iframe", containing some HTML.
But you never use that string, except when calling
iframe.show(0, 0, 207, 50);
which most likely gives you an error because strings have no .show()
function.
Parallel to that you create an iframe:
var oframe = document.createElement('iframe');
Assign it some contents:
var oDocument = oframe.document;
oDocument.open();
var sHTML = "<html><head><link rel='stylesheet' type='text/css' href='../style.css'></head><body topmargin=0 rightmargin=0 leftmargin=0 bottommargin=0 style='overflow:visible;border-width:0px;'>"
+ oMenuDropDown.innerHTML + "</body></html>";
oDocument.write(sHTML);
oDocument.close();
But then that's it, you don't do anything with it.
And if the error you get really says oDucument
, then it must be outside of the code you show here, because there is no oDucument
at all.
Also, oDocument
is undefined
because oframe.document
doesn't exist, it's oframe.contentWindow.document
, but even that will only be available after the iframe has been added to the DOM tree and has finished loading.
A much simpler solution would be to use a data:
URI (see this answer):
function ShowDropdown(oMenu, oMenuDropDown)
{
// Construct the element purely in JS:
var iframe = document.createElement('iframe');
iframe.className = 'adframe';
iframe.id = '111';
iframe.name = 'widget';
iframe.width = 300;
iframe.height = 250;
iframe.marginWidth = 0;
iframe.marginHeight = 0;
iframe.frameBorder = 0;
iframe.scrolling = 'no';
// Set the position:
iframe.style.position = 'absolute';
iframe.style.top = '50px'; // Change this value to what you need
iframe.style.left = '300px'; // Change this value to what you need
// Set the contents:
var sHTML = '<html><head><link rel="stylesheet" type="text/css" href="../style.css"></head><body topmargin="0" rightmargin="0" leftmargin="0" bottommargin="0" style="overflow:visible;border-width:0px">' + oMenuDropDown.innerHTML + '</body></html>';
iframe.src = 'data:text/html;charset=UTF-8,' + encodeURI(sHTML);
// Show popup:
document.body.appendChild(iframe);
}
Also, consider removing the oMenu
parameter since you're not using it.