Skip to content
Related Articles

Related Articles

HTML | DOM Base target Property
  • Last Updated : 26 Mar, 2019

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.






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

Output:
Before Clicking on Button:

After Clicking on Button:

Example 2: This example sets the base target Property.




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

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

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :