jeet_sen wrote:
My Iframe contains a link. This link is actually a local text file. I
made this link to call a function openWindow to display the content of
the local file in a new window. e to a text file.
......
I defined the openWindowd function in contents.src .i.e detailBox.html
Where I am going wrong?
If you need to load some url in the iframe and add additional elements
after it, you should not use document.write() method because it opens
and clears the document(of course, if the document is not in the
process of being opened and written). The additional elements have to
be added as objects (use document.createElement()).
function loadFrame()
{
var contents = document.createElement('IFRAME');
contents.id="frmId";
contents.src="frame.htm";
document.body.appendChild(contents);
//set delay before element addition
setTimeout("addAdditionalElements()", 50);
}
function addAdditionalElements()
{
var f = document.getElementById("frmId");
var div = f.contentWindow.document.createElement("DIV");
div.innerHTML = "<a
href='javascript
:openWindow(\"http://some.html\");'>Click</a>";
f.contentWindow.document.body.appendChild(div);
}
There is an important aspect of referencing a newly created window. IE
tends to race ahead of script execution (presumably to improve
performance). The downside of this feature is that in the case of a
newly created external object, a reference to the new object may not be
valid when the subsequent statements execute in the shadows. To prevent
this race-ahead execution from causing script errors, you need to place
statements referencing the object in a separate function that begins
executing after the current function thread completes. The setTimeout()
method is the mechanism that assists in this task.
Besides, I advise to remove space in a new window name in the
openWindow() function:
new_window = window.open(url,'Logdetails'..
instead of
new_window = window.open(url,'Log details'...
It cause "Invalid argument" error in IE.