Link targets MCQs Quiz | Class 10
This quiz is designed for **Class X** students, covering **Computer Applications (Code 165)**, specifically from **Unit 2: HTML**. The topic is **Link targets MCQs Quiz | Class 10**, focusing on the `target` attribute and the concept of opening links in new tabs or windows. Test your knowledge, submit your answers to see your score, and download a detailed answer PDF for revision.
Understanding Link Targets in HTML
In HTML, hyperlinks are created using the `` tag. These links allow users to navigate between different web pages or sections within a page. A crucial aspect of controlling how a linked document opens is the `target` attribute. This attribute specifies where the linked document will open when the user clicks on the link.
The `target` Attribute
The `target` attribute is used within the `` (anchor) tag to define the browsing context (a window, a tab, or an iframe) in which the linked document should open. It gives you control over the user’s navigation experience.
Example: <a href="https://www.example.com" target="_blank">Visit Example</a>
Common `target` Values
There are several predefined values for the `target` attribute, each with a specific behavior:
- `_self` (Default): This is the default behavior if no `target` attribute is specified. It opens the linked document in the same browsing context (the same window or tab) that the link was clicked. This is generally preferred for internal links to keep users on your site.
- `_blank` (New Window/Tab): This value opens the linked document in a new, unnamed browsing context (typically a new browser window or tab). It is commonly used for external links so that the user’s current page remains open.
- `_parent`: If the link is inside an iframe, `_parent` opens the linked document in the parent browsing context of the current one. If there is no parent (i.e., the link is not in an iframe), it behaves like `_self`.
- `_top`: This value opens the linked document in the topmost browsing context (the full browser window), breaking out of any framesets. If there are no frames, it behaves like `_self`.
- `framename`: You can also specify a custom name (e.g., `target=”myiframe”`). This will open the linked document in the iframe or window with that specific name. If a browsing context with that name does not exist, a new one will be created.
When to Use `_blank` (Open in New Tab/Window)
The `target=”_blank”` attribute is powerful but should be used judiciously.
| Scenario | Reason for `_blank` |
|---|---|
| External Websites | Keeps users on your current site while allowing them to explore external resources. |
| Downloadable Files | Prompts download without navigating away from the current page. |
| Large Media/PDFs | Opens content in a new view, preserving the user’s position on the main site. |
| Special Features (e.g., Maps) | Dedicated views for interactive elements. |
Security and Best Practices with `_blank`
When using `target=”_blank”`, it’s crucial to include `rel=”noopener noreferrer”` for security and performance reasons:
- `noopener` (Security): Prevents the new page from accessing the `window.opener` property of the opening page, which could be exploited for “tabnabbing” phishing attacks.
- `noreferrer` (Security/Privacy): Prevents the browser from sending the `Referer` header to the new page. This enhances privacy by not revealing the source of the click.
Correct Usage: <a href="external.html" target="_blank" rel="noopener noreferrer">External Link</a>
`target` Attribute with Forms
The `target` attribute can also be used with the HTML `