tags:

views:

1958

answers:

1

Hi All,

In my struts2 application I want to open a new window when user click on a link available on jsp page.

I don’t want to user window.open() function of javascript and anchor tag i.e <s:a href=””>.

Onclick control should goto action class, after some processing there it should open a new window.

Please help if it is possible.

+3  A: 

Well, if you don't want to use neither anchor nor window.open() (why?) your only other option is to use "target" attribute on a form and submit it:

<form name="..." method="..." action="..." target="_blank">

Be warned that:

  1. It's deprecated in HTML 4.01 and not supported in XHTML strict.
  2. That window WILL open and control will be transferred to it. You can't suddenly decide in your action that you don't want to open that window; the best you can do is try to close it.

Details on "target" attribute are here. Once again, both window.open() and <a href="..." target="..."> seem like better solutions - why are you opposed to using them?

ChssPly76
ChssPly76, Thanks 4 ur reply. Actually, before opening a new window I want to fetch some entries from database and then these entires will appear in new opened window(.jsp). As, window.open() directly opens a new window so useless. Ya, before viewing your reply I have used anchor tag like<s:url id="blogs" action="someAction"><s:param name="autoId" value="autoId"/></s:url><s:a href="%{blogs}" target="_blank">GoToBlog (2)</s:a>Its running well. But now I want to fix the new opened window size and it should not show anything like internet explorer menus, address bar, refresh etc. HELP.
vivmal
The only way to control window size / attributes is via window.open() function. I'm not sure why you say it's "useless" - you can pass a URL to your JSP with whatever parameters to window.open() method, e.g. `window.open("http://mysite.com/full_path/someAction?autoId=autoId", "blogs", "menubar=0,status=0,width=350,height=250")`. Your action will be invoked and you can do whatever you want - like load stuff from DB - before rendering the output to that window.
ChssPly76
I agree ChssPly76, but I can't provide any URL initially like window.open("url"), I have to provide only actionName and that action will go to my struts.xml there xml will decide that control will goto which action class (.java) and that action class will do some processing with DB and return error/input/success etc. to struts.xml then struts.xml will declare which new window will open (i.e jsp page). Suggest... its running interesting...
vivmal
Well.. its done... instead of providing my jsp path I write my action name in window.open function like -<s:a href="#" onclick="window.open('myAction','','width=700,height=500')">and its following the same flow control that i have written in my previous comment. Thanks.
vivmal