как сделать всплывающее окно по центру

У меня есть страница jsp, которая вызывает функцию getModify() в файле утилиты.js. эта функция выполняет какое-то действие и перенаправляет некоторые значения на следующую страницу jsp с помощью window.open().. я получаю другую страницу jsp в виде всплывающего окна.. как получить всплывающее окно в центре экрана.

мой JSP:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script src="script/Utility.js" data-dojo-config="parseOnLoad: true"></script>
</head>
<body>
<div dojotype="dijit.MenuBarItem" id="SearchMenu21" onclick="getModify();" style="font-size:11pt;" title="menuBarItem">
               <img class="images" id="SearchMenu21" name="search5.png" onclick="setImgProperty(this.id)" src="images/uploads/search.png" style="height:20px; width:20px;">
               Modify
</div>
</body>
</html>

вот мой файл утилиты.js:

function getModify(){
    var whereCondn = "";
    //alert(gbshowgridFlag);
    if(dijit.byId('dynamicgridCWPROCESS')){
        var selctedItem = dijit.byId('dynamicgridCWPROCESS').selection.getSelected();
        if(selctedItem.length){
            dojo.forEach(selctedItem, function(selectedItem){
                if(selectedItem !== null){
                    dojo.forEach(dijit.byId('dynamicgridCWPROCESS').store.getAttributes(selectedItem), function(attribute){
                        var value = dijit.byId('dynamicgridCWPROCESS').store.getValues(selectedItem, attribute);
                        //alert(value);
                        if(attribute == "PROCESS_ID"){
                            whereCondn = whereCondn+attribute+"="+value;
                        }
                        //alert("new alert"+whereCondn);
                        window.open("modifyTask.jsp?MODIFY="+response,'title','height=600px,width=800px,scrollbars=no,sizable=yes,toolbar=no,statusbar=no');
                    });
                }
            });
            //alert("grid row selected");
        }else{
            alert("grid row not selected");
        }
    }
    if(gbshowgridFlag==false){
        alert("grid not loaded");
    }
}

person Rachel    schedule 28.01.2013    source источник


Ответы (2)


Вы также можете передать свойства «top» и «left» для всплывающего окна.

window.open("modifyTask.jsp?MODIFY="+response,'title','height=600px,width=800px,scrollbars=no,sizable=yes,toolbar=no,statusbar=no,top='+ topVar + ',left='+leftVar);

Используйте расчеты на основе screen.height и оптимального размера всплывающего окна, чтобы определить topVar и leftVar.

person DhruvPathak    schedule 28.01.2013

Пожалуйста, попробуй:

var x = screen.width / 2 - 800 / 2;
var y = screen.height / 2 - 600 / 2;
window.open("modifyTask.jsp?MODIFY="+response,'title' ,'height=600px,width=800px,scrollbars=no,sizable=yes,toolbar=no,statusbar=no,left=' + x + ',top=' + y);
person Munish Poonia    schedule 28.01.2013