<td align="center"><img src="image/首页 1.png" width="920" height="960" alt="example1" usemap="#exampleMap1" id="exampleImg1"/></td> </tr> </tbody> </table> <map name="exampleMap1"> <area shape="rect" coords="730,47,791,83" href="#" onclick="openPopup('image/登录与注册 2.png')"> <script> function openPopup(imgPath) { var popupWidth = 689; var popupHeight = 609; var leftPos = (window.innerWidth - popupWidth) / 2; var topPos = (window.innerHeight - popupHeight) / 2; var popupWindow = window.open(imgPath, "popupWindow", "width=" + popupWidth + ", height=" + popupHeight + ", top=" + topPos + ", left=" + leftPos);弹出新窗口后如何对新窗口html进行编写
时间: 2023-07-06 19:04:50 浏览: 84
实验3 客户端脚本编程1
在弹出的新窗口中,可以通过以下方式对新窗口的 HTML 进行编写:
1. 在新窗口中使用 JavaScript 对 HTML 进行修改:
```javascript
var popupWindow = window.open(imgPath, "popupWindow", "width=" + popupWidth + ", height=" + popupHeight + ", top=" + topPos + ", left=" + leftPos);
popupWindow.document.write("<html><head><title>New Window</title></head><body><h1>Hello World!</h1></body></html>");
```
2. 在原始页面中定义一个隐藏的 div 元素,将需要在新窗口中展示的 HTML 内容放到这个 div 中,然后在新窗口中使用 JavaScript 获取这个 div 的内容并插入到新窗口的 body 中:
```html
<div id="popupContent" style="display:none;">
<h1>Hello World!</h1>
</div>
<script>
var popupWindow = window.open(imgPath, "popupWindow", "width=" + popupWidth + ", height=" + popupHeight + ", top=" + topPos + ", left=" + leftPos);
var content = document.getElementById("popupContent").innerHTML;
popupWindow.document.body.innerHTML = content;
</script>
```
无论哪种方式,都可以在新窗口中动态地生成 HTML 内容。
阅读全文