2016-12-15 67 views
-2

定义,我有以下代码:javascript函数不是为td标签

<td valign="top">null 
 
<script type="text/javascript"> 
 
function viewStack1355381490(){ 
 
     var StackWindow = window.open("about:blank", "", "toolbar=0,width=800,height=400,resizable=yes,scrollbars=yes"); 
 
     StackWindow.document.write("<HTML><HEAD>"); 
 
     StackWindow.document.write("<LINK rel=stylesheet href=/oss.css>"); 
 
\t StackWindow.document.write("<TITLE>Stack Trace</TITLE>"); 
 
\t StackWindow.document.write("</HEAD><BODY>"); 
 
\t StackWindow.document.write("<PRE>"); 
 
\t StackWindow.document.write("blablabla"); 
 
\t StackWindow.document.write("</PRE>"); 
 
\t StackWindow.document.write("<br/><br/><b><a href='' onClick='self.close()'>Close Window</a></b><p>"); 
 
\t StackWindow.document.write("</BODY></HTML>"); 
 
} 
 
</script>&nbsp;&nbsp;&nbsp; 
 
<a href="javascript:viewStack1355381490()">[<u><b>Exception</b></u>]</a> 
 
</td>

当我点击链接的异常,我得到这个错误:viewStack1355381490 is not defined。你能帮我找到原因吗?

+0

你没有得到那个错误。它说*“Uncaught TypeError:不能读取null的属性'文档'*。由于您正尝试在函数内读取该属性,因此函数已被定义。 – Quentin

+0

我得到'Uncaught TypeError:无法读取未定义的属性'文档',因为StackWindow未定义。 – iHasCodeForU

回答

0

你忘了定义StackWindow这应该是

var StackWindow; 

工作之一,如下所示:

<td valign="top">null<script type="text/javascript">function viewStack1355381490(){ 
 
     var StackWindow; 
 
     StackWindow = window.open("about:blank", "", "toolbar=0,width=800,height=400,resizable=yes,scrollbars=yes"); 
 
     StackWindow.document.write("<HTML><HEAD>"); 
 
     StackWindow.document.write("<LINK rel=stylesheet href=/oss.css>"); 
 
     StackWindow.document.write("<TITLE>Stack Trace</TITLE>"); 
 
     StackWindow.document.write("</HEAD><BODY>"); 
 
     StackWindow.document.write("<PRE>"); 
 
     StackWindow.document.write("blablabla"); 
 
     StackWindow.document.write("</PRE>"); 
 
     StackWindow.document.write("<br/><br/><b><a href='' onClick='self.close()'>Close Window</a></b><p>"); 
 
     StackWindow.document.write("</BODY></HTML>"); 
 
}</script> 
 
\t <a href="javascript:viewStack1355381490()">[<u><b>Exception</b></u>]</a> 
 
</td>

而且,你会得到

Uncaught TypeError: Cannot read property 'document' of undefined

,因为window.open在沙盒框架中不允许,但未启用允许弹出式权限,但它应对直接文档起作用。

+0

我在'StackWindow'声明中加了'var',但没有帮助。我仍然有这个错误在控制台 –

+0

@wind_gan什么是错误? – nmnsud

+0

'VM603:1 Uncaught ReferenceError:viewStack135538​​1490 is not defined(...)' –