Open In App
Related Articles

HTML | DOM Base target Property

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

The Base target Property in HTML DOM is used to set or return the value of the target attribute of a <base> element. The target attribute is used to specify the default target for all hyperlinks and forms in the page. 

Syntax: 

  • It returns the Base target property.
baseObject.target
  • It is used to set the Base target property.
baseObject.target = "_blank|_self|_parent|_top|framename"

Property Values: 

  • _blank: It is used to open a link in a new window.
  • _self: It is the default value. It is used to open a link in the same frame.
  • _parent: It is used to open a link in the parent frameset.
  • _top: It open a link in the full body of the window.
  • framename: It opens a link in the name dframe.

Return Value: It returns a string value which represents the default target for all hyperlink and forms in the page. 

Example 1: This example returns the base target Property. 

HTML

<!DOCTYPE html>
<html>
<head>
    <base id="Geek_Base"
        href="https://www.geeksforgeeks.org" target="_self">
    <title>
        HTML | DOM Base target Property
    </title>
</head>
<body style="text-align:center;">
    <h1 style="color:green;">
            GeeksForGeeks
    </h1>
    <h2>HTML | DOM Base target Property</h2>
    <button onclick="myGeeks()">
        Click
    </button>
    <h4 id="Geek_p" style="color:green;font-size:24px;"></h4>
     
    <!-- Script to return DOM Base target Property -->
    <script>
        function myGeeks() {
             
            var x = document.getElementById("Geek_Base").target;
             
            document.getElementById("Geek_p").innerHTML = x;
        }
    </script>
</body>
</html>

                    

Output: 

Before Clicking on Button:

  

After Clicking on Button:

  

Example 2: This example sets the base target Property. 

HTML

<!DOCTYPE html>
<html>
<head>
    <base id="Geek_Base" href=
    "https://www.geeksforgeeks.org" target="_self">
    <title>
        HTML | DOM Base target Property
    </title>
</head>
 
<body style="text-align:center;">
    <h1 style="color:green;">
            GeeksForGeeks
    </h1>
    <h2>HTML | DOM Base target Property</h2>
    <button onclick="myGeeks()">
        Click
    </button>
    <h4 id="Geek_p" style="color:green;font-size:24px;"></h4>
     
    <!-- Script to set DOM Base target Property -->
    <script>
        function myGeeks() {
  
            var x = document.getElementById("Geek_Base").target
                = "_blank";
             
            document.getElementById("Geek_p").innerHTML
                = "The value of the target attribute was "
                + "changed to " + x;
        }
    </script>
</body>
</html>

                    

Output: 

Before Clicking on Button: 

 

After Clicking on Button:

  

Supported Browsers: The browser supported by DOM base target property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


Last Updated : 22 Aug, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads