Search code examples
javajavascripthtmlstrutsframe

Page is not loaded in targetFrame


I have a page design where it involves some frames, on the left frame I have menu on which if I click it has to go to other frame, but it is not getting loaded to specified frame instead it is getting loaded in to the same frame where the link is specified.

I create hyperlink as follows in java code.

left_menu_HTML.append("<a href=\"#\" target=\"workFrame\" onclick=\"getMenuRequest('"+model.getResource_name()+"','goToHome')\">"+model.getMenu_name()+"</a>");

I use struts 1.2.9 when the user clicks on the link i call the action like this

function getMenuRequest(actionName,methodName){
   document.forms[0].action=actionName+".htm";
   document.forms[0].method.value=methodName;
   document.forms[0].submit();
}

and the method in action class looks like this

public ActionForward goToHome(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    //call method to verify Pagetoken
    forwardRequestTo = "departmentHome";
    return mapping.findForward(forwardRequestTo);
}

and mapping for this

<action path="/common/DepartmentAction"  name="SecurEyesForm" type="com.secureyes.eswastha.struts.action.DepartmentAction" scope="request" parameter="method" validate="false">
    <forward name="departmentHome" path="/WEB-INF/Masters/DepartmentMaster.jsp"></forward>            
</action>

This is how the frame is aligned ;

</head>
    <frameset border="0" frameborder="0" framespacing="0" rows="64,*">
            <frame border="0" frameborder="0" framespacing="0" id="topFrame" name="topFrame" src="<%=resourcePath%>/common/header.jsp" marginheight="0" marginwidth="0" noresize="noresize" scrolling="no">
            <frameset border="0" frameborder="0" framespacing="0" id="MainFrameSet" cols="209,*">
                    <frame noresize="noresize" border="0" frameborder="0" framespacing="0" id="leftFrame" name="leftFrame" src="<%=resourcePath%>/common/left_menu.jsp" scrolling="auto">
                    <frame border="0" frameborder="0" framespacing="0" id="workFrame" name="workFrame" src="<%=resourcePath%>/common/WelcomePage.jsp" marginheight="7" marginwidth="7" noresize="noresize" scrolling="auto">
            </frameset>
    </frameset>
</html>

Please help me to resolve this,

don't know and can't understand why it is getting loaded in to the same frame .


Solution

  • The code seems fine.

    Which kind of DTD are you using ? Because, according to W3C specs,

    1) The target attribute IS SUPPORTED in HTML5.

    2) The target attribute IS DEPRECATED in HTML 4.01.

    3) Frames and framesets are not supported in HTML5, so the _parent, _top and framename values are now mostly used with iframes.

    EDIT:

    You SHOULD (you better do ;) have defined, in the first row of your jsp page, a DTD to say the browser how to interprete your code. If you don't specify it, the browser go in Quirks Mode, and try to "predict" the page's DTD by its content (with misterious results). If you do specify it, then you must respect the "rules" for that DTD, that you can find on W3C site. They're All liste on wikipedia by the way:

    http://en.wikipedia.org/wiki/Document_Type_Definition

    And this is how a DTD looks like:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    

    FYI, you can validate your page, based on the selected DTD, on the official W3C validator page: http://validator.w3.org/#validate_by_input

    Hope that helps