网页前端后台技巧(CSS+HTML)

form的target属性作用域的问题

2018-08-15  本文已影响3人  sakura_na

当设置form的target属性为iframe的name时,浏览器查找iframe的范围并不只是form所在body中的iframe,而是_top页面及子孙页面中全部iframe。
测试如下:

图片.png
a2为iframe a1中的iframe页面,在a2页面中提交form,form的target设置为b2,b2为iframe b1中的iframe,点击提交按钮,可以看到b2跳转成功,如下图:
图片.png
index.html
<html>
  <body>
    index page
    <iframe name="a1" src="a1.html" width="100%" height="200"></iframe>
    <iframe name="b1" src="b1.html" width="100%" height="200"></iframe>
  </body>
</html>

a1.html

<html>
  <body>
    a1 page
    <iframe name="a2" src="a2.html" width="100%" height="100" />
  </body>
</html>

b1.html

<html>
  <body>
    a2 page, form target is b2, action is http://www.baidu.com.
    <form target="b2" action="http://www.baidu.com">
      <input type="submit"/>
    </form>
  </body>
</html>

a2.html

<html>
  <body>
    b1 page, below frame is b2.
    <iframe name="b2" width="100%" height="100" />
  </body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读