打开指定大小的新窗口
生活随笔
收集整理的這篇文章主要介紹了
打开指定大小的新窗口
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
使用JavaScript打開一個(gè)彈出窗口,可以使用window對象的open()方法或showModalDialog()方法完成。
JavaBean類
OpenCenterWindow類
public class OpenCenterWindow {/*****************************************功能:該方法將生成一個(gè)字符串,該字符串用于輸出自定義的JavaScript函數(shù)(該函數(shù)用于打開指定大小的新窗口,并居中顯示)****************************************/public String open(String url,String w,String h,String no){String str="<script language='javascript'>function openwin"+no+"(){";str=str+"if ("+w+"=='0'){var winhdc=window.open('"+url+"');";str=str+"var width=0;var height=0;}else{";str=str+"var winhdc=window.open('"+url+"','','width="+w+",height="+h+"');";str=str+"var width=(screen.width-"+w+")/2;";str=str+"var height=(screen.height-"+h+")/2;}";str=str+"winhdc.moveTo(width,height);";str=str+"}</script>";return str;}}index.jsp頁面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><base href="<%=basePath%>"><title>My JSP 'index.jsp' starting page</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body><!-- 導(dǎo)入打開窗口的JavaBean類 --><jsp:useBean id="myWindow" class="com.cn.zj.test.ShowWindow"></jsp:useBean><!-- 設(shè)置打開窗口的JavaScript函數(shù)名 --><jsp:setProperty property="functionName" name="myWindow" value="openWindow1"/><!-- 設(shè)置打開窗口的url地址 --><jsp:setProperty property="url" name="myWindow" value="window.jsp"/><!-- 設(shè)置打開窗口的寬度 --><jsp:setProperty property="width" name="myWindow" value="200"/><!-- 設(shè)置打開窗口的高度 --><jsp:setProperty property="height" name="myWindow" value="100"/><!-- 獲得打開窗口的JavaScript函數(shù)字符串 --><jsp:getProperty property="openWindowStr" name="myWindow" /><form action="window.jsp" method="post"><input type="button" value="打開窗口" onclick="openWindow1()"/></form></body> </html>window.jsp頁面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><base href="<%=basePath%>"><title>打開窗口</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css">body{font-size: 15px;color:green;font-family: 隸書;background-color: pink;}</style></head><body>你好!我是被打開的新窗口!寬度200px,高度100px,居中顯示。</body> </html>總結(jié)
以上是生活随笔為你收集整理的打开指定大小的新窗口的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 弹出提示对话框并重定向网页
- 下一篇: 在Servlet中实现页面转发