读书人

拒绝访问 js,该怎么处理

发布时间: 2012-05-29 12:16:00 作者: rapoo

拒绝访问 js
我用iframe嵌套一个页面,主要是为了实现Ajax上传的功能,页面代码如下:

HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditAdProcLinkInfo.aspx.cs" Inherits="EnMng_SProMng_Page_Ad_EditAdProcLinkInfo" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>无标题页</title><script language="javascript" type="text/javascript">// <!CDATA[function uploadFile(){    alert("ok");        if(document.readyState == "complete" && ifu.document.readyState == "complete"){        //ifu.document.form1.submit();        var obj = document.frames[0];        obj.document.getElementById("btnSubmit").click();    }    else    {        alert("sdfsd");    }    }function btnSave_onclick() {    if(document.getElementById("txtUrl").value == "")    {        alert("请输入链接地址!");        return false;    }    if(document.getElementById("filePic").value == "")    {        alert("请选择图片路径!");        return false;    }    if(document.getElementById("fileFlash").value == "")    {        alert("请选择Flash路径!");        return false;    }    uploadFile();      return false;    //<%=Page.ClientScript.GetCallbackEventReference(this, string.Empty, "getSaveCalBack", string.Empty) %>;}function getSaveCalBack(str){    alert(str);}function btnCancle_onclick() {window.parent.parent.GB_hide();}// ]]></script></head><body >    <form id="form1" runat="server">       <div>        <div >            <table style="width: 100%; height: 100%">                <tr>                    <td style="height: 22px" >                        企业代码:</td>                    <td style="height: 22px" >                    <input type="text" id="txtCid" name="txtCid" readonly="readOnly" value ="<%= cid %>" />                    </td>                    <td style="height: 22px" >                        产品代码:</td>                    <td style="height: 22px" >                    <input type="text" id="txtPsid" name="txtPsid" readonly="readOnly" value="<%= psid %>" />                    </td>                </tr>                <tr>                    <td style="height: 50px" >                        链接地址:</td>                    <td style="height: 50px" >                    <input type="text" id="txtUrl" name="txtUrl" /><span style="color:Red;">*</span>                    </td>                    <td style="height: 50px" >                        链接图片:</td>                    <td style="height: 50px" >                    <input type="text" id="filePic" readonly ="readonly" />                        <input type="button" value="浏览..." onclick="javascript:filePic.value=ifu.getLoadUrl();" />                            <span style="color:Red;">*</span>                    </td>                </tr>                <tr>                    <td style="height: 50px" >                        链接Flash:</td>                    <td style="height: 50px" >                    <input  type="text" id="fileFlash"  readonly="readonly"/>                    <input type="button" value="浏览..." onclick="javascript:fileFlash.value=ifu.getLoadUrl();" />                        <span style="color:Red;">*</span>                    </td>                    <td style="height: 50px" >                    </td>                    <td style="height: 50px" >                    </td>                </tr>                <tr>                    <td style="height: 50px" >                    </td>                    <td style="height: 50px" >                    <input type="button"  value="确 定" id="btnSave" onclick="return btnSave_onclick()" />                                                   <input type="button"  value="取 消" id="btnCancle" onclick="return btnCancle_onclick()" />                    </td>                    <td style="height: 50px" >                    </td>                    <td style="height: 50px" >                    </td>                                    </tr>            </table>                    </div>    </div> <iframe src="Upload.aspx" frameborder="0" id="ifu" name="ifu" style="width: 577px; height: 58px"></iframe>    </form></body></html> 



这个是主页面,嵌套UPload.aspx页面,Upload.aspx页面代码如下:
HTML code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpLoad.aspx.cs" Inherits="EnMng_SProMng_Page_Ad_UpLoad" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>无标题页</title>    <script type="text/javascript">    function SubmitForm()    {   alert("i am in");        //this.document.form1.submit ();        document.forms[0].submit();    }        function getLoadUrl()    {        document.getElementById("myFile").click();        return document.getElementById("myFile").value;    }</script></head><body>    <form id="form1" runat="server"  >    <div >    <input type="file" runat="server" id="myFile" name="myFile" style="visibility:hidden;"   />         <input type="button" id="btnSubmit" name="btnSubmit" onclick="SubmitForm()"  style="visibility:hidden;" />     </div>    </form></body></html>


现在遇到的问题就是总是报js拒绝访问错误,我测试到alert("i am in");
这行都可以正常运行,就是到document.forms[0].submit();
这行的时候就报 拒绝访问了,我这两个文件时放在一个文件夹里面的,不存在跨域的问题吧??~~~但是Upload.aspx提交表单就报错,我试过在主页面中提交Upload.aspx的表单ifu.document.form1.submit(); 也是拒绝访问,还望高手指点小弟,这个问题到底该如何解决??~先谢过了~~

[解决办法]
把file隐藏了然后通过JavaScript调用是不允许的
可直接使用updatepanel实现ajax下文件上传
看看AjaxFileUploadHelper组件
[解决办法]
用url参数获取。或者不用Iframe
[解决办法]
document.forms[0].submit() 这个可能有问题,因为有两个document了,个人意见哈

[解决办法]
路过帮顶~
[解决办法]
对于file控件,必须点击它本身才可以完成文件的上传,其他方式都是无效的。

读书人网 >asp.net

热点推荐