Issue with loading content on Google Chrome/Safari

I have a variety of links that trigger bootstrap modals. Some modals have simple html content, while others contain an iframe.

To determine which type of content to load into the modal, I am using ng-switch. However, there seems to be an issue only in Google Chrome and Safari (webkit browsers).

Within the iframe, I am utilizing the onload attribute to execute a function once the iframe is ready.

<div class="modal-body" ng-switch="modal.type">
   <div ng-switch-when="iframe">
      <iframe ng-src="http://plunker.co/group" onload="callMeMaybe();"></iframe>
   </div>
   <div ng-switch-when="html">
      <h1>This is just plain html.</h1>
   </div>
</div>

The problem: Chrome and Safari are calling the onload function twice, whereas Firefox and IE are behaving correctly by calling it just once.

What steps can I take to prevent this issue from occurring in Chrome/Safari?

Check out the example on Plunkr

Answer №1

It seems that on webkit browsers, the onload event for an iframe is triggered twice - first when the iframe is created and then again when the src is set.

As mentioned in this answer:

To prevent this behavior, you can attach the onload event after appending your iframe element to the body. However, implementing this solution in your specific scenario may be a bit challenging.

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

A guide on updating pseudo-class values dynamically using CSS

Imagine a scenario where there is a navigation panel named <div class="nav"> containing 5 anchor links <a>. CSS: .nav a:nth-of-type(1) { text-decoration: underline; } The objective is to switch the underlined element by adjusting the CSS ...

javascript floating point calculation

Can anyone help me with calculating float values in JavaScript? Here is a snippet of my code: var d_val = 0.00; $.each($('.prices a b'), function(index,obj){ d_val = parseFloat( $(obj).text().replace( '€', '' ) ); ...

Tips for troubleshooting JSONP AJAX events

I've been encountering some issues with a JSONP AJAX request that I'm trying to make. Despite my attempts to troubleshoot, the request doesn't seem to work as expected. Here is the code snippet that I've been using: $.getJSON(server_pa ...

establish a connection with the node server and initiate the automatic mask detection feature

Here's my issue: I have a node server running a game I'm developing. The server listens on an IP address in the network, such as 192.168.x.x (which can vary). The game "frontend" is a web page hosted on a domain (like paperplane.io) that links ...

Authentication in HTML5 beyond the internet connection

Seeking feedback on the most effective way to control access to an HTML5 application that is primarily used offline. This application utilizes IndexedDB, local, and session storage to securely store data for offline use, all served via HTTPS. The main go ...

"Implementation of clearInterval function may not always result in clearing the interval

The scrolling process within the div element flows smoothly in both directions, however, it seems to encounter an issue when executing the scrollBack() function. Despite including a clearInterval() statement at the intended point, the interval does not a ...

Modal not opening when activated from Foundation Foundation

I am encountering difficulty in triggering the Reveal modal, and I cannot figure out the issue. Initially, I suspected a JavaScript conflict. To troubleshoot, I stripped down the site to its essentials: some CSS, some JS, and some HTML. However, even afte ...

List-group item in Bootstrap 4 featuring an arrow on the right side

Currently, I am utilizing Bootstrap 4 and are in need of developing a list-group featuring a title as well as an arrow positioned on the right side. This is what I currently have: <div class="accordion" id="accordionExample"> & ...

The express.js GET method is unable to retrieve the value of req.body

I have experience working with Vue3, Vuex, Express.js, and MySQL. In the code snippet below, when I use the router get method, I noticed that calling "console.log(req.body)" displays "[object Object]", and calling "console.log(req.body.userid)" shows "unde ...

Discover the best way to utilize the leaflet marker cluster group feature!

I am struggling to create a leaflet marker cluster group and adding all the markers to it. Below is the code I have written, but I keep encountering the error TypeError: L.markerClusterGroup is not a constructor I can't figure out if there is an issu ...

The compatibility between JSON and the CORS header 'Access-Control-Allow-Origin' is crucial

I am trying to obtain the value from a JSON file that is located on the server. To retrieve this value, I am using AJAX. However, when checking the console for errors, I receive the following message: Cross-Origin Request Blocked: The Same Origin Poli ...

Revamp the sequence of divs using jQuery

<div class="example first">111</div> <div class="example second">222</div> <div class="example third">333</div> Can the order of these divs be changed using jQuery? I am looking to get: <div class="example second"&g ...

Utilizing Checkbox to Filter Data in Javascript

Looking for guidance on Javascript as a beginner. I'm attempting to filter and update data based on checkbox selections. The issue lies with Dataset3, where I aim to update the dataset dynamically once checkboxes are selected or deselected. I am stru ...

The JavaScript and CSS properties are not functioning properly with the HTML text field

I came across this CodePen example by dsholmes and made some modifications: Here Furthermore, I have developed my own form on another CodePen pen: Link The issue I'm facing is related to the placeholders/labels not disappearing when typing in text f ...

What is the best way to trigger an onclick event for an input element with a type of "image"?

In the code I'm working on, there's an input of type "Image". <div class="icon" id="button_dictionary"> <form> <input class="buttonDictionary" type="image" src="icone_dicionario.jpg" value="" id="inputDictionary"> ...

What is the method to enable Google Adsense to reach pages within a restricted login area that utilizes JSON authentication?

I am looking to place Google Adsense ads on my website, but I want them to only appear within a specific area that is accessible to users after they log in. Within the Google Adsense interface, I have explored the Account Settings -> Access and authori ...

Analyzing two arrays and utilizing ng-style to highlight matching entries within the arrays

My list displays words queried from a database, allowing me to click on a word to add it to another list that I can save. This functionality enables me to create multiple word lists. My goal is to visually distinguish the words in my query list that have a ...

Jade form submission results in an empty req object

Can't Retrieve Data in Express extends layout block content h1= title form(action="create", method="post") div.input span.label Enter Username input(type="text", name="username") div.input ...

Is there a way to trim HTML code while still maintaining the integrity of the closing tags?

Is there a way to create a blog post preview from HTML by properly closing the tags without rendering the whole content on the frontend? Currently, I am using react's dangerouslySetInnerHTML and setting styles like overflow: hidden and height: 150px. ...

Is there a way to modify the value of a constructor key once it has already been defined?

I am currently working on a simple constructor exercise where I need to update a value after the constructor has been created. Even after changing the value to true, the cat is still not making its noise. Challenge parameters The constructor function wi ...