When using the <object> tag, it may not always render at 100% height as intended

Application Inquiry

I am seeking assistance with a web page that features a title, and a sticky menu bar at the top, allowing the rest of the space for displaying content. When a menu item is clicked, the objective is to load a page in the content at full width and height. However, after executing the loadPage script, only 8 lines of height are displayed. I have attempted several solutions from both stackoverflow and Google, without success. Even using an iframe did not result in 100% width and height coverage.

Please assist me in resolving this issue. Thank you in advance.

function loadPage(docName) {
  if (!document.getElementById("mainFrame"))
    return false;
  document.getElementById("mainFrame").innerHTML = '<object type="text/html" width="100%" heigth="100%" data="' + docName + '"></object>';
}
window.onscroll = function() {
  myFunction();
};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;

function myFunction() {
  if (window.pageYOffset >= sticky) {
    navbar.classList.add("sticky")
    document.getElementById("navbar").style.marginTop = "0px";
  } else {
    document.getElementById("navbar").style.marginTop = "30px";
    navbar.classList.remove("sticky");
  }
}
html,
body {
  height: 100%;
  min-height: 100%; 
  width:100%;
  margin: 0;
  font-size: 14px;
  font-family: Arial, Helvetica, sans-serif;
}

#titleFrame {    
  position: absolute;
  top: 0;
  left: 0;
  height: 30px;
  line-height: 30px;
  width: 100%;
  font-weight: bold;
  overflow: hidden;
  /* Disable scrollbars. Set to "scroll" to enable*/
  text-align: center;
  color: white;
  background: navy;
}

#navbar {
  overflow: hidden;
  background-color: #333;
  height: 24px;
  line-height: 24px;
  width: 100%;
}

#navbar a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  font-weight: normal;
  padding: 0px 16px;
  text-decoration: none;
  font-size: 14px;
}

#navbar a:hover {
  background-color: #ddd;
  font-weight: bold;
  color: black;
}

#navbar a.active {
  background-color: #4CAF50;
  color: white;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
}

li {      
  float: left;
  border-right: 1px solid #bbb;
}

li:last-child {
  border-right: none;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 0px 16px;
  text-decoration: none;
}

li a:hover:not(.active) {
  background-color: #111;
}

.active {
  background-color: #4CAF50;
}

.sticky {
  position: fixed;
  top: 0;
  width: 100%;
}

.sticky+.content {
  padding-top: 54px;
}
<div id="titleFrame">Welcome to the CyberPlaypen</div>
<div id="navbar" style="margin-top: 30px;">
  <ul>
    <li><a href="#home">Labs</a></li>
    <li><a href="#ctfest">CTFest</a></li>
    <li><a href="#training">CodeFest</a></li>
    <li><a href="#powershack" onclick="loadPage('CyberPlaypenDoc.html');">PowerShack</a></li>
    <li><a href="#toolsoft">ToolSoft</a></li>
    <li><a href="#training">Training</a></li>
... 

Answer №1

Ensure the height is set for mainFrame and object tag

#mainFrame {
    height: 100%; 
}

#mainFrame object {
    height: 100%; 
}

Sample Scenario

function loadPage(docName) {
  if (!document.getElementById("mainFrame"))
    return false;
  document.getElementById("mainFrame").innerHTML = '<object type="text/html" width="100%" heigth="100%" data="' + docName + '"></object>';
}
window.onscroll = function() {
  myFunction()
};
var navbar = document.getElementById("navbar");
var sticky = navbar.offsetTop;

function myFunction() {
  if (window.pageYOffset >= sticky) {
    navbar.classList.add("sticky")
    document.getElementById("navbar").style.marginTop = "0px";
  } else {
    document.getElementById("navbar").style.marginTop = "30px";
    navbar.classList.remove("sticky");
  }
}
/* new */
#mainFrame {
    height: 100%;
}

#mainFrame object {
    height: 100%;
}

/* original */

html,
body {
  height: 100%;
  min-height: 100% width:100%;
  margin: 0;
  font-size: 14px;
  font-family: Arial, Helvetica, sans-serif;
}

#titleFrame {
  /* Welcome to the CyberPlaypen */
  position: absolute;
  top: 0;
  left: 0;
  height: 30px;
  line-height: 30px;
  width: 100%;
  font-weight: bold;
  overflow: hidden;
  /* Disable scrollbars. Set to "scroll" to enable*/
  text-align: center;
  color: white;
  background: navy;
}

#navbar {
  overflow: hidden;
  background-color: #333;
  height: 24px;
  line-height: 24px;
  width: 100%;
}

#navbar a {
  float: left;
  display: block;
  color: #f2f2f2;
  text-align: center;
  font-weight: normal;
  padding: 0px 16px;
  text-decoration: none;
  font-size: 14px;
}

#navbar a:hover {
  background-color: #ddd;
  font-weight: bold;
  color: black;
}

#navbar a.active {
  background-color: #4CAF50;
  color: white;
}

ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333;
}

li {
  float: left;
  border-right: 1px solid #bbb;
}

li:last-child {
  border-right: none;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 0px 16px;
  text-decoration: none;
}

li a:hover:not(.active) {
  background-color: #111;
}

.active {
  background-color: #4CAF50;
}

.sticky {
  position: fixed;
  top: 0;
  width: 100%;
}

.sticky+.content {
  padding-top: 54px;
}
<div id="titleFrame">Welcome to the CyberPlaypen</div>
<div id="navbar" style="margin-top: 30px;">
  <ul>
    <li><a href="#home">Labs</a></li>
    <li><a href="#ctfest">CTFest</a></li>
    <li><a href="#training">CodeFest</a></li>
    <li><a href="#powershack" onclick="loadPage('https://zh.wikipedia.org/wiki/Wiki');">PowerShack</a></li>
    <li><a href="#toolsoft">ToolSoft</a></li>
    <li><a href="#training">Training</a></li>
    <li><a href="#contact">Contact</a></li>
    <li style="float:right"><a href="#about">About</a></li>
  </ul>
</div>
<div id="mainFrame">
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint
    efficiantur his ad. Eum no molestiae voluptatibus. Some text to enable scrolling.. Lorem ipsum dolor sit amet,
  </p>
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint
    efficiantur his ad. Eum no molestiae voluptatibus. Some text to enable scrolling.. Lorem ipsum dolor sit amet,
  </p>
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint
    efficiantur his ad. Eum no molestiae voluptatibus. Some text to enable scrolling.. Lorem ipsum dolor sit amet,
  </p>
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint
    efficiantur his ad. Eum no molestiae voluptatibus. Some text to enable scrolling.. Lorem ipsum dolor sit amet,
  </p>
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint
    efficiantur his ad. Eum no molestiae voluptatibus. Some text to enable scrolling.. Lorem ipsum dolor sit amet,
  </p>
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint
    efficiantur his ad. Eum no molestiae voluptatibus. Some text to enable scrolling.. Lorem ipsum dolor sit amet,
  </p>
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint
    efficiantur his ad. Eum no molestiae voluptatibus. Some text to enable scrolling.. Lorem ipsum dolor sit amet,
  </p>
  <p>Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint
    efficiantur his ad. Eum no molestiae voluptatibus. Some text to enable scrolling.. Lorem ipsum dolor sit amet,
  </p>
</div>

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

Issue with Bootstrap flash alert CSS on mobile devices is not functioning properly

I am in the process of developing a Rails application. Within my app, I utilize Bootstrap's CSS for displaying flash messages on alerts. Instead of fully incorporating Bootstrap's CSS, I only integrate styles related to alerts in order to prevent ...

Issue with Angular App: Bootstrap navbar not displaying on smaller screens

I am working on an Angular app (using Angular 11.2.4 with Bootstrap 4.5.3) and facing an issue where the navbar is not rendering correctly on screens smaller than ~580 pixels wide. Even when I click the toggler to 'expand' the collapse region, n ...

A guide on extracting checkbox value from a database in PHP through the use of the explode function

I have a form with three checkboxes where some people select all subjects and others select only two. I need to retrieve the checkbox values from the database. Below is my current code. If anyone knows the solution, please share. <?php $connection = ...

What is the specified height for the AppBar and Toolbar components in Material-UI?

I'm trying to figure out the exact height being used in this scenario: <AppBar position="static"> <Toolbar> because I'll need that information for a calculation in another component. My current assumption is that it's 64px, b ...

setting the child div's margin in relation to its parent div

Here is my HTML: <div class='mainDiv'> <div class='subDiv'></div> </div> This is the corresponding CSS code: .mainDiv { margin-top: 200px; width: 700px; height: 800px; background-color: red ...

Highlight the parent name in the menu when I am on the corresponding child page

Here is a snippet of a recursive function: function recursive($arrays, $out) { if (is_array($arrays)){ //$out .= "<ul>"; foreach($arrays as $parent => $data) { //if parent is empty if ($parent === '') { ...

How to display an image in a pop-up with a title

I am currently using the Bootstrap framework and I am trying to create a popup image with a title, but it only shows the image. I am not sure how to add code in JavaScript to display the title as well. Can someone please assist me? Here is my code: Javas ...

What is the process of triggering an email send via a button click in Django?

As a newcomer to Django, I am facing issues accessing the view via ajax code. The code is triggered by a button click and is supposed to send an email. In my view.py file, the code in the 'def error' block should display when there's an erro ...

Is the homepage the only page rendering correctly?

After working on an MVC project for over 6 months, I consistently faced a problem with HTML and CSS. The homepage always rendered correctly, as shown here: http://prntscr.com/tucp1 However, all other pages had strange white spaces between words, like in t ...

Incorporating CSS into React.js applications

I am currently working on a project using MERN.io. In my project, I am utilizing the React.js component Dropdown. However, the Dropdown component does not come with its own style and CSS, resulting in no styling at all. ... import Dropdown from 'rea ...

Looking to verify a disabled select element and adjust the opacity of that element when it is disabled

$_product = $this->getProduct(); $_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes()); ?> <?php if ($_product->isSaleable() && count($_attributes)):?> <dl> <?php foreach($_attrib ...

The results of the query are not showing up on the website

I am encountering an issue with a query/output that is not functioning as expected. Despite ensuring the accuracy of all column table names, no errors are being thrown by PHP error checking. Below is the code segment that is failing to produce any output: ...

A step-by-step guide on changing the class of a focused contenteditable element with a button click using jQuery

I need assistance changing the class of an element within a contenteditable div. Here is my current code: <button>swap class</button> <div contenteditable="true"> <h1 class="line-height-1">Your Headline Here</h1> </di ...

Guide on adding up the value of a property within an array of objects using AngularJS

I am receiving an array of results from a Node.js API in my Angular app, and here is how it looks: <div *ngFor="let result of results"> <div *ngIf="result.harmattan.length > 0"> ... </div> <br> .. ...

Unable to interact with a button element of type="button" using Selenium, but successful with elements of type

In my attempt to interact with the webpage, I am specifically focusing on this button: <button class="button-text-like marg-l-0 float-l desktop-only remove-button" data-bind="click: $root.removeCartItem" type="button"> <i class="gicon-cross">& ...

Submitting a form with multiple actions using Ajax

Is it possible to submit data from multiple forms on the same page to different API tables using AJAX for each form? I have one form that needs to write to one table and another form that needs to write to a different table. How can I achieve this with o ...

Changing pricing on pricing table with a click

Looking to implement a price changing button that functions similar to the one found at this LINK: If anyone knows of any JavaScript or other solution, please provide me with some guidance. Thank you in advance. ...

Adjust the wait time for sliding on the jQuery rcarousel

I am currently utilizing rcarousel for my website and I would like to adjust the duration of time that each slide is displayed. At the moment, each slide stays up for just a few seconds, but I want to extend this so that each slide remains on screen for at ...

Steps to easily set up a date-range-filter in Angular 6!

I have put together a small StackBlitz project to showcase my current situation. My aim is to log all objects that fall within a specified date range. However, when I attempt to filter my objects, I am faced with an empty array as the result. I would like ...

Ensure that any modifications made to an Angular service are reflected across all components that rely on that service

I am currently in the process of replicating a platform known as Kualitee.com, which serves as a test-management tool utilized by QA Engineers. Within Kualitee, users can access multiple projects, each containing various test cases and team members. The ab ...