Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Tuesday, July 31, 2007

Popup windows in JSF

Is is possible to raise a popup window in Java Server Faces (JSF) using Javascript, more or less the same way as in HTML.

This example shows how this can be done with a commandButton.

<h:commandButton value="Press me to bring up a popup window" onclick="window.open('popup.jsp', 'popup_window')" />

This exact method won't work with a commandLink, because this does not offer an onclick option. However the mouseup event can be used instead:

<h:commandLink onclick="window.open('popup.jsp', 'popup_window')">
    Press me to bring up a popup window
</h:commanndLink>

Of course, both commandButton and commandLink items need to be enclosed in a form element. This means that the form will be submitted when the commandButton or commandLink is pressed/clicked. In order to avoid it, we have to return false from within the onclick or mouseup attribute.

<h:commandButton value="Press me to bring up a popup window" onclick="window.open('popup.jsp', 'popup_window'); return false;" />

Wednesday, July 18, 2007

Javascript context menus

With Javascript it is possible to add a context menu to an object (ie a menu that displays on right-click). However, on Firefox, right-clicking on an object with a custom context menu will show both this menu and the normal Firefox context menu. The Firefox context menu is displayed on top of the custom menu, so in order to access the latter, you need to click somewhere else on the page, in order to access the custom menu.

This behaviour can be overridden by selecting the following options:
Edit → Preferences → Content → Advanced (next to Enable Javascript) → Disable or replace context menus.

Tuesday, June 5, 2007

Javascript: Button redirect

An eas way to redirect to another page (in the same window) is through the parent.location Javascript variable.
<INPUT TYPE="button" onClick="parent.location='url'">
The URL can be either relative or absolute.
Note: Credit to this site: http://winfolinx.com/tips/howto/redirect/redirbut.htm