0

I have pop.jsp in which there is two div tag when i click on FindByid then only find by id field show and if i click on findByname then that field show only which is perfectly working .But the problem is that when i open a pop sometimes none of the field visible or sometime it smoothly works i don't know why it's happen i want to visible the respective field on click of button accordingly

note sometimes visibility of div tag perfectly is working only on internet explorer for other browsers no div tag is visible so plz resolve my problem

here is my index.jsp pop code through which i mopenieng pop up

<script type="text/javascript">
function windowLoadByName(windowHeight, windowWidth) {
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    newWindow = window.open(
            'PopUp.jsp',
            'mywindow',
            'resizable=0,width=' + windowWidth + ',height=' + windowHeight
                    + ',left=' + centerWidth + ',top=' + centerHeight,
            "status=1").divHiding(1);
    newWindow.focus();

}
function windowLoadById(windowHeight, windowWidth) {
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;
    newWindow = window.open(
            'PopUp.jsp',
            'mywindow',
            'resizable=0,width=' + windowWidth + ',height=' + windowHeight
                    + ',left=' + centerWidth + ',top=' + centerHeight)
            .divHiding(2);

    newWindow.focus();
    return newWindow.name;
}

and this is my pop.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/input-1.0"
    prefix="input"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
    function loadByName() {
        var l = document.getElementById("firstName");
        var v = l.value;
        window.opener.loadName(v);
        window.close();
    }
    function loadById() {
        var ids = document.getElementById("id");
        var v = ids.value;
        window.opener.loadId(v);
        window.close();
    }

    function divHiding(id) {

        var div1 = document.getElementById('div1');
        var div2 = document.getElementById('div2');


        // Check what the value of the button pressed and displays the correct div
        if (id == 1)
            div1.style.display = 'block';
        else if (id == 2) {
            div2.style.display = 'block';
        }
    }
</script>
</head>
<body>

    <form name="employeeForm" method="get">
        <div id="div1" style="display: none;">
            Employee Name:
            <center>
                <input type="text" name="firstName" id="firstName" />
            </center>
            <center>
                <input type="submit" name="Search" value="Search"
                    onclick="loadByName()" />
            </center>
        </div>
        <div id="div2" style="display: none;">
            Employee Id:
            <center>
                <input type="text" name="firstName" id="id" />
            </center>
            <center>
                <input type="submit" name="Search" value="Search"
                    onclick="loadById()" />
            </center>
        </div>
    </form>

</body>

</html>
4

1 に答える 1

0

問題は、window.open(..) で divHiding 関数を呼び出しているためです。関数が呼び出されたときにページが読み込まれない可能性があります。これが、機能する場合と機能しない場合がある理由です。私が提案する解決策は、表示したい div を url パラメータで渡すことです。

newWindow = window.open(
            'PopUp.jsp?div=1',
            'mywindow',
            'resizable=0,width=' + windowWidth + ',height=' + windowHeight
                    + ',left=' + centerWidth + ',top=' + centerHeight)

popup.jsp では、以下のコードを実行してパラメーターが 1 であるかどうかを確認し、div1 を表示に設定し、div2 に対して同じことを行うことができます。

<div id="div1" style="display: <%=(request.getParameter("div").equals("1") ? "block" : "none") %>;">
于 2013-01-24T07:39:36.767 に答える