Anchor targetProperty

Anchor 对象参考手册Anchor Object

Definition and Usage

The target property sets or returns the value of the target attribute.

The target attribute specifies where to open the linked document.

Syntax

Set the target property:

anchorObject.target="value"

Return the target property:

anchorObject.target

Value Description
_blank Load the document in a new, unnamed window.
_self Load the target document in the same frame or window.
_parent Load the document into the parent window or the frameset that contains the hyperlink reference.
_top Load the document into the window containing the hyperlink, replacing any frames currently displayed in the window.
framename Load the document in the same frame.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the target attribute.


Example

Example

Change the target of a link:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Example (example.com)</title> <script> function changeTarget(){ document.getElementById('example').target="_blank"; } </script> </head> <body> <a id="example" href="//www.example.com">Visit Example</a> <br><br> <input type="button" onclick="changeTarget()" value="Modify target"> <p>Try clicking the link before you click the button.</p> </body> </html>

Try it yourself »


Anchor 对象参考手册Anchor Object Other Extensions