Monday, September 22, 2008

Form.target

Use Case: Sometimes you may want a form to be processed and the result displayed in a different window (popup->main, main->popup).

target is a read/write string property of the Form object. It specifies the name of the frame or window in which the results of the submission of form should be displayed. Four special target names are supported: _blank, _parent, _self and _top.


<script>
function openwin() {
  window.open("about:blank", "winDocPrint", "..size,etc");
}
</script>


<form action="printdoc.php?sa=<?php echo session_id(); ?>" target="winDocPrint" onsubmit="openwin">
...
</form>

** sa=<?php echo session_id(); ?> is URL rewriting used to keep the same session in the new window. And session_start() must be invoked on new window to resume the current one based on the current session id that's being passed via a request.

No comments: