没有为td标记定义javascript函数

时间:2016-12-15 09:41:01

标签: javascript html

我有以下代码:



<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>");
	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>&nbsp;&nbsp;&nbsp;
<a href="javascript:viewStack1355381490()">[<u><b>Exception</b></u>]</a>
</td>
&#13;
&#13;
&#13;

当我点击Exception链接时,我收到此错误:viewStack1355381490 is not defined。你能帮我找到原因吗?

1 个答案:

答案 0 :(得分: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>
	<a href="javascript:viewStack1355381490()">[<u><b>Exception</b></u>]</a>
</td>

此外,你会得到

  

未捕获的TypeError:无法读取未定义的属性“文档”

因为在没有启用allow-popups权限的情况下沙盒框架中不允许window.open,但它应该适用于直接文档。