Skip to main content
Version: Next

WP NEW BOOKMARK

WP NEW BOOKMARK ( targetObj ; bkName )

ParameterTypeDescription
targetObjObjectRange or element
bkNameTextName of bookmark to create

Description

The WP NEW BOOKMARK command creates a new bookmark named bkName based upon the 4D Write Pro targetObj in the parent document.

Bookmarks are named references to ranges or elements, which allow you to access and reuse specific parts of the document, for example for templating purposes. For more information, please refer to the Bookmark commands section.

In targetObj, you can pass:

  • a range belonging to the body (see below), or
  • an element (body / table / row / inline picture / paragraph)

Note: If you passed an element in targetObj, the bookmark will contain only the specified element.

In bkName, pass the name for the new bookmark. A bookmark name must be compliant with HTML/CSS names, i.e. it must only contain alphanumeric characters (invalid characters, such as space characters, are automatically removed). Bookmark names must be unique within the document. If a bookmark with the same name already exists in the document, it is overwritten.

You can create as many bookmarks as you want within the same document. Multiple bookmarks can be created using the exact same range. Once created, a bookmark is automatically stored in the parent document and is saved with the document itself.

warning

Bookmarks can only be created from ranges within the body of the document, i.e. they cannot be created from a range in the header, footer, or a text box of a document. To make sure a range belongs to the body, check its wk container attribute: it is null or undefined for body ranges.

Example 1

You want to create a new bookmark referencing the currently selected text in the document. You can write:

 var $range : Object
 $range:=WP Selection range(*;"WPDocument")
 WP NEW BOOKMARK($range;"my_bookmark")

Example 2

You want to rename an existing bookmark. To do this, you need to create a new bookmark with the same range, and then delete the old one:

 var $bookmarkOldName : Text
 var $bookmarkNewName : Text
 var $p : Integer
 var $wpRange : Object
 
 $bookmarkOldName:="MyBookmark"
 $bookmarkNewName:="MyNewBookmark"
 
 ARRAY TEXT($_bookmarks;0)
 WP GET BOOKMARKS(WParea;$_bookmarks)
 
 $p:=Find in array($_bookmarks;$bookmarkOldName)
 If($p>0)
    $wpRange:=WP Get bookmark range(WParea;$bookmarkOldName)
    WP DELETE BOOKMARK(WParea;$bookmarkOldName)
    WP NEW BOOKMARK($wpRange;$bookmarkNewName)
 End if

See also

WP Bookmark range
WP DELETE BOOKMARK
WP GET BOOKMARKS