What are the steps to verify if an iframe is lacking content?

I have two different codes: one is null and the other is not null.

Code with null value (== empty):

<div class="col-xs-6">
    <iframe style="width:868px; height:550px;" id="FileReload" src="/Account/GetPDF?NUM=101">
        <html>
            <head></head>
            <body>
                <pre style="word-wrap: break-word; white-space: pre-wrap;"></pre>
            </body>
        </html>
    </iframe>
</div>

Code when not null (!= empty):

<div class="col-xs-6">
    <iframe style="width:868px; height:550px;" id="FileReload" src="/Account/GetPDF?NUM=101">
        <html>
            <body style="background-color: rgb(38,38,38); height: 100%; width: 100%; overflow: hidden; margin: 0">
            <embed width="100%" height="100%" name="plugin" id="plugin" src="http://localhost:49943/Account/GetPDF?NUM=101" type="application/pdf" internalinstanceid="74" title="">
            </body>
        </html>
    </iframe>
</div>

Controller code:

public ActionResult GetPDF(int NUM)
{
    //.Select Database
    //.
    //.
    if (reader.HasRows)
    {
        //Check if it passes a null or not-null value
        PDF = ((byte[])reader["File"]);
        return new FileContentResult(PDF, "application/pdf");
    }
}

When it is null, the iframe displays as white. If it is not null, it works fine. (I want to hide the iframe when the layout is white.)

Here is how it looks when the iframe is white:

https://i.stack.imgur.com/6TYhq.jpg

If the value is null, display a white iframe with specified width and height.(if == null -> hide the iframe)

How can I check if a value is null using JavaScript?

Answer №1

Success! I've cracked the code!

$(function() {
  $('#FileReload').load(function() {            
    if ($.trim($(this).contents().find("body").find('embed').length) == 0) {
      $(this).hide();
    }
  });
});

Even though it employs jQuery, there's no need to fret

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

Angular appears to be having trouble with localStorage functionality

Having an issue with my service that interacts with a local NOTES object array using localStorage. Whenever the page refreshes, the previously entered data is lost and only the initial data in the const NOTES array remains. Can't seem to figure out wh ...

Please type the file name into the provided text box

Is there a way to automatically insert the filename of an uploaded file into an existing text input using either or valums.com/ajax-upload/? (I am working with php) For example, in a textbox: <input name="image" type="text" value="file_name" /> ...

Encountering difficulty in retrieving the outcome of the initial HTTP request while utilizing the switchMap function in RxJS

My goal is to make 2 HTTP requests where the first call creates a record and then based on its result, I want to decide whether or not to execute the second call that updates another data. However, despite being able to handle errors in the catchError bl ...

Stop the execution of javascript code based on the screen width

On my website, I have two menus located in different sections of the page. One menu is shown when the screen width is greater than 555px, while the other menu appears when the screen width is less than or equal to 555px. Although the menus are essentially ...

Passing array data from JavaScript to PHP using POST method in Joomla 3.x

Looking for a way to send an array from JavaScript to a Joomla 3.x PHP file? var data = ['foo', 'bar']; $.post('index.php?option=component&view=componentview&Itemid=123&tmpl=component&layout=xlsx', {'xls ...

To view the previous or next image, simply click on the links and watch as the new image fades in seamlessly while maintaining

Whenever I click on a prev/next link, a specific div loads different images that loop. The JavaScript successfully changes the image source when the prev or next button is clicked. It works flawlessly. However, I am facing an issue. I want each new image ...

Exporting JavaScript formatting in Netbeans is a breeze

Does anyone know how to preserve the formatting for JavaScript in Netbeans 8.1 when exporting? After clicking on the export button and expanding Formatting, I couldn't find any option specifically for JavaScript. I've thought about locating the ...

Form fields will not automatically populate with link parameters; the user must manually input the information

My form fetches data from the database using server-side code when the user inputs the "user_id" field. The User ID field is the primary field on the form, and when the user enters their user ID, all other fields retrieve the corresponding user data from t ...

JavaScript Memoization: Enhancing Performance Through Caching

Recently, I delved into various JavaScript design patterns and stumbled upon memoization. While it seems like an effective way to prevent redundant value calculations, I can't help but notice a flaw in its implementation. Consider the following code s ...

Issue with Titanium: Unable to scroll within tableview

The tableview is not scrolling as expected. I tested it on a mobile device and the scrolling worked fine, but it doesn't seem to work on tablets. Please assist. CODE var win = Titanium.UI.createWindow({ title : 'Medall app', back ...

A tool developed in Javascript that allows for the conversion of .ini files to .json files directly on the client

Does anyone know of a JavaScript library that can convert .ini files to .json files on the client-side? I checked out this library, but it doesn't meet my requirements. Here is an example of an .ini file: [Master_Settings:1] Model Name=RC-74DL IP Ad ...

Create a smooth scrolling effect for a div with a fixed position

Having trouble scrolling a fixed position div on the page? Are you using this jquery script: $('html, body').animate({ scrollTop: $(".example").offset().top }, 750); I had to set the body overflow property to hidden for another issue. The ...

A guide on linking an object in strapi V4 to a React app

Recently in strapi v4, there was a change in the response API structure from an array to an object. When analyzing the response using Postman on my local strapi API and converting it into raw format with stringify, I noticed that the API response consists ...

Axios transforms into a vow

The console.log outputs of the api and axios variables in the provided code are showing different results, with the state axios becoming a Promise even though no changes were made. The 'api' variable holds the normal axios instance while 'ax ...

Trying out a React component that relies on parameters for connection

Having an issue while attempting to test a connected react component that requires a props.params.id in order to call action creators. During the testing process, when checking if the component is connected to the store, an error "Uncaught TypeError: Canno ...

The delay in loading HTML content using FOSJsRoutingBundle and Ajax for a specific route parameter (ID)

I'm using FOSjSrouting in my symfony2.7 project. This is the code in my html.twig view: <table> <!--table header code ...etc... --> <tbody> {% for currentData in arrayData %} <tr> <td>{{ currentData. ...

Error: Unable to access 'createInvite' property from undefined variable

Having trouble generating an invite to one of my guild's channels. Here is the code snippet I am using: const { Client } = require("discord.js"); const client = new Client({ intents: [] }); client.on("ready", async () => { ...

A Vue component library devoid of bundled dependencies or the need for compiling SCSS files

My current challenge involves the task of finding a way to publish our team's component library. These components are intended to be used by various internal applications within our organization. I have specific requirements: The library must be acc ...

What is the correct way to import the THREE.js library into your project?

I recently added the three library to my project via npm. Within the node_modules directory, there is a folder named three. However, when I tried to import it using: import * as THREE from 'three'; I encountered the following error: ReferenceEr ...

Issues with JQuery list selectors

Many individuals have raised concerns about selectors in the past, but no matter what I try, my code seems right yet it doesn't work as intended. My situation involves a list of actions that are displayed or hidden when their corresponding "folder" is ...