Linking to a different webpage within HTML code

If I have two separate HTML files named footer.html and main.html. The footer file includes a link to the top of a page like this:

<!-- footer.html -->

<!doctype html>
<html lang="en">
<head></head>
<body>
  <footer>
    <small><a href="_parent#header">To top</a></small>
  </footer>
</body>
 </html>

The main.html file is set up to include the footer using the <object> tag (refer to note 1). There could be multiple files similar to main.html, so using <a href="page#header"> may not work.

<!-- main.html -->

<!doctype html>
<html lang="en">
<head></head>
<body>
  <div id="header">...</div>
  <div id="content"> Long content ... </div>
  <object id="footer" type="text/html" data="footer.html"></object>
</body>
</html>

Question: Is there a way to reference the anchor from the footer in the main file without relying on javascript, php, etc?

Note 1: Using the <object> tag allows for embedding another HTML document without creating a direct relationship between them:

You can also use the <object> tag to embed another webpage into your HTML document. source: http://www.w3schools.com/tags/tag_object.asp

A similar approach can be taken with <iframe> or <embed> instead of <object>, but the challenge remains.

Answer №1

Is there a way to reference the anchor from the footer to main without relying on JavaScript or PHP?

Unfortunately, no.

If you opt for a relative URL, it will be relative to the document where the link is placed (in this case, the footer).

Using an absolute URL would require specifying the exact document you wish to link to (but given that multiple documents may include the footer, this approach isn't feasible).

You've already dismissed the possibility of dynamically generating the URL using JavaScript.

Answer №2

Appreciate all the feedback and suggestions. It appears that the previous method was unsuccessful due to a lack of connection between HTML files. Essentially, footer.html couldn't reference the internal content of main.html. To resolve this, I restructured the layout so that the footer is directly included in the main file and the content is displayed using an <iframe> like so:

<!-- main.html -->

<!doctype html>
<html lang="en">
<head></head>
<body>
  <div id="header">...</div>
  <iframe id="content" name="contentframe" src="content.html"></iframe>
  <footer id="footer">
    <small><a href="#" target="_self">Back to top</a></small>
  </footer>
</body>
</html>

This modification resolves the issue and functions without relying on JS, PHP, or any other scripting languages regardless of the content loaded into the <iframe>. In essence, it smoothly scrolls back to the top while preserving the content of the loaded page. This setup works seamlessly with Firefox and Internet Explorer.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Stylish Titles with Bootstrap

I have been trying to eliminate the border that is creating the panels Body, but I am encountering some difficulties in locating it. Here is the code snippet for my panel: <div class="panel"> <div class="panel-heading"> <span class ...

Extracting text or value from a <span> element using its unique ID and storing it in a variable from a different website using cURL in

I am trying to retrieve the value or text within a span with a specific id from an external website using cURL. Once I have obtained this value, I need to store it in a variable. Here is an example of the span I am looking for: <span id="company" clas ...

Changing the color of an element on click using jQuery's .css() method,

There is a table and I am using fadeToggle on the list to hide and show the table. The background of the list is green color, but I want to change the list color when hiding the table and revert it back to green when clicking to show the table. Unfortunate ...

Customize Bootstrap 4 table by incorporating d-flex class and changing border color styling for a

Currently utilizing bootstrap 4.0, I am attempting to customize the table-bordered by changing the color and incorporating d-flex with col-* for column sizing. An issue arises where all borders become duplicated when attempting to modify the color scheme. ...

The CSS element is covering up the Xpath element

I am grappling with a challenge in my Selenium testcase as a temporary CSS element is blocking the xpath element I need to click on. During the execution of my testcase in Visual Studio, I encounter an error message that reads: OpenQA.Selenium.ElementCli ...

Having trouble with submitting a form using jQuery?

I have created a form on my website: <form action="thanks.php" onsubmit="return false" class="submitForm"> ... Various input fields ... </form> Additionally, I have included a jQuery script: $(document).ready(function() { $("form.subm ...

"Want to learn how to create divisions that start on a new line in your HTML/CSS

Is it possible to limit the number of divs displayed per row? I'm working on a Django project and would like to have a maximum of 3 divs per row. Ideally, this would automatically create a new line after every third div without using JavaScript. Any s ...

Choose from the options provided to display the table on the screen

One of the challenges I am facing involves a table with two columns and a select option dropdown box. Each row in the table is associated with a color - green indicates good, red indicates bad, and so on. My goal is to have all values displayed when the pa ...

Comparing Traditional Tables to Div Tables

Is this process: <table> <tr> <td>Hello</td> <td>World</td> </tr> </table> Achievable with the following code? <div> <div style="display: table-row;"> <di ...

Is there a way to customize the text color in a dynamic AJAX Barchart display?

I'm working on creating a bar chart using AJAXToolkit to showcase data related to our system. However, I'm facing an issue with changing the color of the text within the chart. The text is currently in black against a grey background, making it d ...

To enhance user experience, consider incorporating a 'Next Page' feature after the completion of every four paragraphs,

Here is a code snippet that can be used to print 'n' number of paragraphs: <% while(rs.next()){ String para=rs.getString("poems"); %> <p> <%=para%> </p> <!-- n number of p tags are printe ...

Issue with SmartNavigation in ASP.NET application using .NET 1.1

I am encountering an issue with a .Net 1.1 webapp where I have an aspx page with the attribute SmartNavigation=true set. Within this page, there is an anchor tag structured like this: <a href='#' onclick="$.copy('ANNUAL PAID OZ');" ...

A guide to building a dynamic form slider that showcases variable output fields with Javascript

I'm interested in creating a Slider Form that shows different output fields when sliding, using Javascript. Something like this: https://i.sstatic.net/3Isl4.png Could anyone provide suggestions on how to achieve this or share any links related to so ...

What is the method for centering text above and below an image in the vertical middle?

I'm struggling to create a vertical center-aligned image gallery on my website with "PREVIOUS" and "NEXT" links for easy navigation. Despite multiple attempts, I can't seem to get it right. Can someone guide me on how to achieve this effect? ...

Utilizing Selenium to automatically scroll through a Flickr page in order to capture and retrieve all the

Hey there! I'm currently working on a project to retrieve Flickr public images from a specific group. So far, I've been able to successfully parse the HTML and extract the image hrefs. However, I'm facing a challenge when it comes to retriev ...

Obtain the selected option from a user list

In my user table, each user is listed with a name, surname, right, and a "commit changes" button. The purpose of this setup is to assign rights to different individuals. Each column contains the userID, and the entire structure is generated from a database ...

Using the .slider class on concealed div elements

Explaining this may be a bit tricky, but here we go... I have multiple hidden divs that switch with each other when a link is clicked using $(document).ready(function(){ $('a').click(function () { var divname= this.name; $("#"+divname ...

Unable to add dynamically created content after deleting all associated elements

In my code, I have a Select element that generates dynamic HTML below it based on the selected value. Before appending the HTML after the year id, I try to remove all elements with the class quarter, but it seems like it's not working properly. $( ...

Create an HTML component that expands to fill any leftover space on the page, without using flex

In my current situation, I have two elements positioned side by side with dynamic widths based on their content. The element on the right needs to fill up as much vertical space as possible without a set width. I am looking for an alternative to flexbox d ...

What are the different ways to customize the indicator color of React Material UI Tabs using hex

Just got my hands on this amazing Material UI component <Tabs textColor="primary" indicatorColor="primary" > <Tab label="All Issues"/> </Tabs> The documentation states that indicatorColor and textColor can only be set to ' ...