views:

55

answers:

1

I have a html form (upload.htm) with a html file upload control inside of it.

<form id="frmupload" name="upload" enctype="multipart/form-data" action="uploadhandler.ashx" method="post">
    <input id="uploader" name="uploadctrl" type="file"/>
</form>

There is also one javascript method in the above page which goes like:

function performUpload(){
    document.getElementById('frmupload').submit();
}

I call this inside of a page (uploadpage.htm) from within an iframe:

<iframe id="docframe" src="upload.htm" style="display:none"></iframe>

I try to execute the statement shown below from the uploadpage.htm page:

var i = document.getElementById('docframe');
i.contentWindow.performUpload();

I get an error saying Access is denied, and my debugger halts at the first javascript function I've shown. Both the files are in the same location in the web project. They have the same domain name too. Why do I get this error then?

Of course, earlier, I could post the page: when I did not set the name attribute for the html upload control. But after I set the name attribute in html markup, I get this weird error. Why didn't I get this the first time?

Had a look @ this post --> http://stackoverflow.com/questions/2276374/access-is-denied-when-script-tries-to-access-iframe-in-ie8, but it didn't help.

A: 

In both the html files - one which is in the frame and another which contains the frame, try adding document.domain='xxx.com' where 'xxx.com' is your domain name.

Gaurav Saxena