使用iframe call server及iframe target使用例

//iframe.htm
<!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>
    <title>Example of remote scripting in an IFRAME</title>
</head>

<script type="text/javascript">
    function handleResponse() {
      alert('this function is called from server.html');
    }
</script>

<body>
    <h1>
        Remote Scripting with an IFRAME</h1>
    <iframe id="beforexhr" name="beforexhr" style=" 0px; height: 0px; border: 0px"
        src="blank.html"></iframe>
    <a href="server.html" target="beforexhr">call the server</a>
</body>
</html>

//server.html
<!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>
    <title>the server</title>
</head>

<script type="text/javascript">
    window.parent.handleResponse();
</script>

<body>
</body>
</html>
运行iframe.html时会把消息显示出来

使用target例:
<html>
<head><title>test target</title></head>
<body>
<iframe width=420 height=330 name=aa frameborder=1 src="http://www.baidu.com">
</iframe>
<a href="http://www.google.com" target=aa>google</a>
<a href="http://www.baidu.com" target=aa>baidu</a>
</body>
</html>

 

原文地址:https://www.cnblogs.com/yansc/p/635064.html