如何在框架中执行 javascript?
我正在尝试在框架标记中编写 JavaScript 代码。但它没有执行我的 JavaScript 代码块。
我这样做的方式是:
<HTML>
<HEAD>
<TITLE>My HomePage</TITLE>
</HEAD>
<FRAMESET id="frameset1" rows="0,100%,0,0,0" frameborder=0>
<FRAME NAME="seat" SRC="seat/seat.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
<FRAME id="main" NAME="main" SRC="main.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
<script type='text/javascript'>
var myVar=1;
</script>
</FRAME>
<FRAME id="seatinfo" NAME="seatinfo" SRC="seatapi/seatinfo/seat_state.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
<FRAME id="blank" NAME="blank" SRC="blank.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
<FRAME id="preloadHelp" NAME="preloadHelp" SRC="preloadHelp.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
当我在 firebug 中检查 top.main.myVar 时,它显示未定义。
I am trying to write javascript code in a frame tag. But it is not excuting my block of javascript code.
The way i am doing this is :
<HTML>
<HEAD>
<TITLE>My HomePage</TITLE>
</HEAD>
<FRAMESET id="frameset1" rows="0,100%,0,0,0" frameborder=0>
<FRAME NAME="seat" SRC="seat/seat.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
<FRAME id="main" NAME="main" SRC="main.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
<script type='text/javascript'>
var myVar=1;
</script>
</FRAME>
<FRAME id="seatinfo" NAME="seatinfo" SRC="seatapi/seatinfo/seat_state.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
<FRAME id="blank" NAME="blank" SRC="blank.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
<FRAME id="preloadHelp" NAME="preloadHelp" SRC="preloadHelp.html" frameborder="no" border=0 MARGINWIDTH="0" MARGINHEIGHT="0" SCROLLING="no" FRAMEBORDER="no" NORESIZE>
When i inspect top.main.myVar in firebug, it displays undefined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要回答您的问题,请研究对 document.frames(或者在框架内工作时为
parent.frame
)。话虽这么说,框架是不好的做法,恕我直言。我强烈建议您不要使用它们。
To answer your question, look into javascript calls to document.frames (or
parent.frame
in the case of working within a frame).That being said frames are bad practice, IMHO. I would strongly encourage you to not use them.
您可以在目标框架中评估代码,而不是直接将代码放置在框架标记中,类似于 next
在这种情况下 myVar 将在目标文档中可用。
Instead of placing code directly in frame tag, you can evaluate your code in target frame, something like next
in such case myVar will be available in the target document.