Opening new window or going back

Ted Husted

To go back a page, you can use a standard JavaScript button.


<input type='button' onclick='history.go(-1);' name="button" value="PRINT" /> 
To popup another window, you can pass whatever parameters you need from the bean to the JavaScript. You can also use custom tags within the JavaScript to render URIs and such.

Here, if the "View Script" link is clicked, we open a window unto the "itemScript" forward, which corresponds to the Struts path "/do/item/script/View".


<a href='javascript:doScript(<bean:write name="itemForm" property="item"/>)'>View Script</a>

<!-- ... -->

<script>
function doScript(aItem) {
  aBase = '<html:rewrite forward="itemScript"/>';
  doOpenRemote(aBase + '?item=' + aItem,'preview','*','600','scrollbars','form');
}
</script>

<script>
function doOpenRemote(aURL, newName, aHEIGHT, aWIDTH, aFeatures, orgName){
  if (aHEIGHT == "*"){ aHEIGHT = (screen.availHeight - 80) };
  if (aWIDTH == "*"){ aWIDTH = (screen.availWidth - 30) };
  var newFeatures = "height=" + aHEIGHT + ",innerHeight=" + aHEIGHT;
  newFeatures += ",width=" + aWIDTH + ",innerWidth=" + aWIDTH;
  if (window.screen){
    var ah = (screen.availHeight - 30);
    var aw = (screen.availWidth - 10);
    var xc = (( aw - aWIDTH ) / 2);
    var yc = (( ah - aHEIGHT ) /  2);
    newFeatures += ",left=" + xc + ",screenX=" + xc;
    newFeatures += ",top=" + yc + ",screenY=" + yc;
    newFeatures += "," + aFeatures
  };
  var newWin = openWin(aURL, newName, newFeatures, orgName);
  newWin.focus();
  return newWin
}
</script>

<script>
function openWin(newURL, newName, newFeatures, orgName) {
  var newWin = open(newURL, newName, newFeatures);
  if (newWin.opener == null)
    newWin.opener = window;
  newWin.opener.name = orgName;
  return newWin
}
</script>
In the new window, to let them print or close the window, again you can just use the typical JavaScript solutions:


<input type='button' onclick='javascript:window.print();' name="button" value="PRINT" /> 
<input type='button' onclick='javascript:window.close();' name="button" value="CLOSE" /> 

Note that we don't bother with the Struts tags here, because they provide no added value. POH (Plain Old HTML) works just fine =:0)

HTH, Ted

--
Ted Husted,
Struts in Action

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact