Upon the second visit, Bootstrap popover functions as expected

After creating a website on SharePoint using Bootstrap and populating the content with JavaScript, I encountered an issue with popover functionality. Oddly enough, the popover only works after refreshing or reloading the page with F5.

Strangely, popovers outside of the table function properly upon initial load, and the code functions without errors on my local machine. However, when transferred to SharePoint, it malfunctions.

Here is the initialization code:

<script src="jquery-3.5.1.slim.min.js"></script>
<script src="popper.min.js"></script>
<script src="bootstrap.min.js"></script>

Followed by the table generation function call:

<body onload="javascript: GenerateTable();">

And then the popper function call:

$(function () {
  $('.example-popover').popover({
  })
})

The outcome is a table with a line containing the following popper:

<td>Here is a question which needs a popper as info!&nbsp;&nbsp;
<div class="row justify-content-end">       
<a href="#!" tabindex="0" class="badge badge-info" role="button" data-toggle="popover" data-trigger="focus" title="" data-content="This is a funny popover" title="Info">Info</a>
</div>
</td>

It appears to be an issue related to loading order, but why it works locally and not on SharePoint remains unclear.

Answer №1

Utilizing external js libraries from a CDN has proven to be effective in my setup. Here is an example of how you can use it:

<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body >
  <td>When there's a query that requires additional information, a popper will help!&nbsp;&nbsp;
    <div class="row justify-content-end">       
    <a href="#!" tabindex="0" class="badge badge-info" role="button" data-toggle="popover" data-trigger="focus" title="" data-content="This is a amusing popover" title="Info" data-placement="right">Info</a>
    </div>
    </td>
    
</body>
<script>

$(function () {
  $('.badge').popover();
 
})
</script>

Result of the test:

https://i.sstatic.net/r6bZ2.gif
If you need more guidance, please provide the complete code.

Answer №2

The issue stemmed from the sequence in which the JavaScript was executed. Since the code is fetched from an external JavaScript file, its loading order is unpredictable.

To address this, it is advisable to encapsulate the JavaScript function in the HTML file within a specific function in the JavaScript file. This function should then be explicitly called.

JavaScript File:

function InitializePopper(){
$('.example-popover').popover({});
$('.popover-dismiss').popover({trigger: 'focus'});
$('[data-toggle="popover"]').popover();
}

In the HTML document, the function can be invoked using:

<body onload="javascript: GenerateTable(); InitializePopper();">

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

Trouble with displaying images in Bootstrap 4 cards

I am currently experimenting with Bootstrap 4 and trying to create cards, but I am facing issues with images not displaying on the cards. Currently, I only have one image in the first card, but it still does not render. You can view the code I have written ...

Generate Random Quotes - Each new quote should be different from the previous one

As I tackle the FreeCodeCamp 'Random Quote Machine' front end library project using React JSX, everything seemed to be running smoothly except for one major issue - the same quote was often generated two or three times in a row. Obviously, this i ...

What is the process for importing the required dependencies for the maps module in react-svg-map?

Exploring interactive maps led me to discover the project react-svg-map. As I followed the example provided, a certain issue caught my attention: import Taiwan from "@svg-maps/taiwan"; The developers mentioned that they have separated the map&ap ...

AJAX chat application's updating frequency

As I work on building a website that includes a feature for real-time chatting between users (similar to Facebook chat), I have implemented a system where messages are stored in a MySQL table called messages. This table contains the message ID, sender ID, ...

What is the purpose of creating a new HTTP instance for Socket.io when we already have an existing Express server in place?

As I delve into SocketIO, I've combed through various blogs and documentation on sockets. It seems that in most cases, the standard approach involves creating an HTTP server first and then attaching the socket to it as shown below: var app = express() ...

Unusual body padding found in the mobile design

When visiting on a mobile device and inspecting the elements in Google Chrome, try disabling the style rule overflow-x: hidden from the body element and then resizing the window. You may notice a white vertical stripe (padding) appearing on the right side ...

Sending data from jQuery modal to the final input field

In my latest project, I have developed a modal window that features a table with rows of input boxes and buttons: <table class="datatable tablesort selectable paginate full" width="100%"> <tbody> ...

Turn off HTML display for Internet Explorer users

I am looking to implement code that will block certain pages for Internet Explorer users, making it accessible only for Google Chrome and Firefox users. Do you have any suggestions on how I can achieve this or if there are existing solutions available? I& ...

Controls that shift a DIV in either direction

I've been working on making a div scroll left or right with either a mouseover effect or click, but I can't seem to figure out what's going wrong. My initial attempt was straightforward: <body> <div id="innerscroll"></div> ...

Unable to install react-dom/test-utils using npm

I recently included two libraries in my package.json "devDependencies": { ... "react-dom/test-utils": "*", "react-test-renderer/shallow": "*" }, These were recommended by the React documentation to align with version 16 of the React ecosy ...

Leveraging Angular 4 component as a custom widget within a static website

Is it possible to integrate my Angular 4 component (a mail window widget application built with webpack) into a static website, ideally utilizing the <script> tag? I came across some blog articles, but they all mention using SystemJS while my app is ...

Implementing jQuery form validation including checking for the strength of the password

My understanding of jQuery was quite basic until I began working on jQuery form validation with password strength check. I successfully completed the password strength check portion, but now I am unsure of how to enable the submit button once the condition ...

I am attempting to utilize Ajax in order to transfer information to a different webpage

It's a bit complex and I can't figure out why it's not working. My goal is to create a page with textboxes, dropdown lists, and a datagrid using easyui. The issue arises when I select something from the dropdown list - I want two actions to ...

Wait for transition to finish before setting focus to text input

How can I ensure that the focus is automatically set to the text input field after a transition has ended? I want the user's keyboard input to immediately go into the text input field. Is it possible to achieve this using only CSS, or do I need to use ...

Can anyone suggest a simple method to decode this JavaScript?

While browsing a website's checkout page, I came across a suspicious Javascript snippet that seemed out of place. It raised concerns that it might be secretly stealing credit card numbers: var R = ['1jBCeMi', '81AdhODE', 'keyd ...

Tips on showcasing a set number of elements from an array in React

How can I modify my code to display only a specific number of items from the 'portfolioComponents' array, starting at a designated index ('startArrayHere') and incrementing or decrementing that index based on user interaction? I've ...

Setting up a winston logger in NestJS - A simple guide!

I am facing an issue with my nestjs app where I am trying to incorporate winston as a logger service. However, this implementation is causing my app to break and I am unsure how to resolve or revert this issue. I have attempted to uninstall the winston pa ...

Create a PDF document with the background of the input text included and printable

I am trying to find a way to make the background image of the input text appear when saving the page as a PDF (right-click, select "Print ...," and then "Save as PDF"). The page has a square background image that creates the effect of each character being ...

What is the best way to run an external JavaScript file at regular intervals?

I enjoy loading an external JavaScript file every 10 seconds, or whenever the page body is clicked (in which case, the script should only run if a few seconds have passed). If you could provide me with some documentation on this topic, that would be grea ...

What steps can I take to pinpoint the exact error location when running assetic:dump in Symfony2?

This error message indicates an issue with assetic:dump in Symfony2. [Assetic\Exception\FilterException] ...