HTML | DOM Base target Property

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 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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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 use DOM Base target Property -->
    <script
        function myGeeks() { 
              
            var x = document.getElementById("Geek_Base").target; 
              
            document.getElementById("Geek_p").innerHTML = x; 
        
    </script
</body
  
</html>                    

chevron_right


Output:
Before Clicking on Button:

After Clicking on Button:

Example 2: This example sets the base target Property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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 use 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>                    

chevron_right


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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.