7.14. Opening Browser Windows with Specific Parameters Using Static Text

Problem

You want to open a new browser window with specific dimensions (and/or other settings) when the user clicks the static text.

Solution

Apply a hyperlink to the text (see Recipe 8.12) in which the URL is in the form of javascript:void(window.open('url', '', 'additional parameters'));.

Discussion

You can invoke JavaScript functions from links associated with static text fields. This technique is applicable only when you have embedded the SWF in an HTML page, and it allows you to call any function that is accessible from within the HTML page, including the window.open( ) JavaScript method that opens a new browser window.

To create the link, select the text and add a value to the URL link field in the form of javascript:void(window.open('url', 'window name', 'additional settings'));. The javascript protocol lets Flash know that you want to invoke a JavaScript function. The void( ) function should enclose the remainder of the command in order to avoid undesirable results, such as extra new windows being opened unexpectedly. Notice that the parameters for the window.open( ) method are in single quotes rather than double quotes. You should always use single quotes when you use this technique. Double quotes will not work properly.

The first parameter that you pass to the window.open( ) method should be the URL you want to open in the new browser window. The value can be either an absolute URL (e.g., http://www.person13.com/fcb ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.