在线求救:Microsoft JScript 运行时错误: 'contentWindow.document' 为空或不是对象

wangrumeng 2006-10-27 10:48:23
页面出现如题的错误,请问这是怎么回事应该怎么解决?注:两个不同的没什么关系的页面都报这个错误?请教各位师兄?
...全文
826 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangrumeng 2006-10-27
  • 打赏
  • 举报
回复
最后一句:Response .Write ("<script>window.parent.location='../default.aspx'</script>");报错
wangrumeng 2006-10-27
  • 打赏
  • 举报
回复
我的代码如下:
.aspx文件
<%@ Page language="c#" Codebehind="UserLoginSuccess.aspx.cs" AutoEventWireup="false" Inherits="NewMovies.Web.Users.UserLoginSuccess" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>UserLoginSuccess</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="../css/main_style.css" type="text/css" rel="stylesheet">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table width="100%" height="34" border="0" cellpadding="0" cellspacing="0" background="../images/index_r1_c5.jpg">
<tr>
<td>
<img src="../images/Forum_readme.gif" width="9" height="9"> 亲爱的用户[<asp:Label id="lbl_userName" runat="server" ForeColor="Red"></asp:Label>]欢迎您登陆!   <a href="EditUserInfoByUsername.aspx" target="_blank">我的网票</a>|
<asp:Label id="Label1" runat="server"></asp:Label>
<a href="UserAccess.aspx?userType=4" target="_blank"></a>| <img src="../images/gif-0027.gif" width="11" height="11"><span class="c"><a href="UserAccess.aspx?userType=5" target="_blank" class="b">我的代金券</a></span></td>
<td><asp:ImageButton ID="img_exit" runat="server" ImageUrl="images/btn_logout.GIF" BorderStyle="none"></asp:ImageButton></td>
</tr>
</table>
</form>
</body>
</HTML>


.aspx.cs 文件
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System .Web .Security ;

namespace NewMovies.Web.Users
{
/// <summary>
/// UserLoginSuccess 的摘要说明。
/// </summary>
public class UserLoginSuccess : System.Web.UI.Page
{
protected System.Web.UI.WebControls.ImageButton img_exit;
protected System.Web.UI.WebControls.Label lbl_userName;
private movies .Business .UserInfo ufo=null;
private Voucher .VoucherUse vc=new Voucher.VoucherUse ();
private ticket .Database db=new ticket.Database ();
protected System.Web.UI.WebControls.Label Label1;
int UserID=0;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string userName=HttpContext .Current .User .Identity .Name .ToString ();
if(userName!="")
{
this.lbl_userName .Text =userName;
try
{
using(ufo=new movies.Business.UserInfo())
{
DataSet ds=ufo.getUserIDbyUsername (HttpContext .Current .User .Identity .Name );
DataTable dt=ds.Tables [0];
if(dt.Rows .Count >0)
{
int UserID=int.Parse (dt.Rows [0][0].ToString ());
db.Connect ();
int aa=vc.VoucherDistribute (db,UserID,"");
}

}
}
catch
{}
finally
{
db.Close ();
}
if(getSysMsg(userName)!=0)
{
// this.HyperLink1 .Visible =true;
this.Label1 .Text ="<img src=\"../images/gif-0037.gif\"> <a href=\"#\" class=\"b\" onClick=\"window.open('SysMessage.aspx','');return false;\"><font color=\"red\">您有新短消息</font></a>";

}
else
{
// this.HyperLink1 .Visible =false;
this.Label1 .Text ="<a href=\"#\" onClick=\"window.open('SysMessage.aspx','');return false;\"><font=\"black\">我的站内短消息</font></a>";

}
}

}

/// <summary>
/// 该用户是否有未读的站内短消息
/// </summary>
/// <param name="userName"></param>
/// <returns>0-没有未读的消息;1-有未读的消息</returns>
private int getSysMsg(string userName)
{

int flag=0;
using(ufo=new movies.Business.UserInfo ())
{
if(userName!="")
{
DataSet ds=ufo.getUserIDbyUsername (userName);
if(ds!=null)
{
DataTable dt=ds.Tables [0];
if(dt.Rows .Count >0)
{
UserID=int.Parse (dt.Rows [0][0].ToString ());
}
}
if(UserID!=0)
{
flag=ufo.isNewCount(UserID);
}
}

}
return flag;
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.img_exit.Click += new System.Web.UI.ImageClickEventHandler(this.img_exit_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

//退出登录
private void img_exit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Session ["UserName"]=null;
FormsAuthentication.SignOut();
Response .Write ("<script>window.parent.location='../default.aspx'</script>");
}
}
}
逍遥散人 2006-10-27
  • 打赏
  • 举报
回复
所以才需要更详尽的代码啊,我的代码:
test.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!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>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
</form>
</body>
</html>

test.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("<script>window.parent.location='default.aspx'</script>");
}
}

如果window.parent.location='default.aspx'的路径指向出错,应该是报"404"的错啊
wangrumeng 2006-10-27
  • 打赏
  • 举报
回复
happyexp(快乐水手):
如果我把这句报错的语句改成:
Response .Write ("<script>window.alert('test');</script>");
则不会报任何错误,请问这又该怎么办呢??
逍遥散人 2006-10-27
  • 打赏
  • 举报
回复
'contentWindow.document' ???我记得在javascript中有window.document,有contentWindow.document这个东东吗?
逍遥散人 2006-10-27
  • 打赏
  • 举报
回复
经过测试,在一个干净的页面下你的这句代码是正确的,所以,页面报错肯定不是这句代码引起的,能不能更详细一点?
wangrumeng 2006-10-27
  • 打赏
  • 举报
回复
怎么没人响应啊????????????????????????
wangrumeng 2006-10-27
  • 打赏
  • 举报
回复
报错语句为:
Response .Write ("<script>window.parent.location='../default.aspx'</script>");
真相重于对错 2006-10-27
  • 打赏
  • 举报
回复
code??/
逍遥散人 2006-10-27
  • 打赏
  • 举报
回复
再问一下,错误是在加载页面时报的还是在点击图片后报的?我用的是2005,你的代码在2005中点击图片时没有触发服务器端事件。
另外,你试试把"Response .Write ("<script>window.parent.location='../default.aspx'</script>");"换成"Response.Redirect("../defalut.aspx");"看看

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧