Detailed explanation of the solution to the problem that the content pointed to by the iframe's src does not refresh

Detailed explanation of the solution to the problem that the content pointed to by the iframe's src does not refresh

Problem Description

html

<iframe id="h5Content" src=""></iframe>

js

$("#h5Content").attr("src","${h5.url}");

h5.url corresponds to a page edited by ueditor and saved in the database.

After modifying the content of this page and submitting it, the page presented in the iframe does not change.

reason

The content in the iframe will be refreshed only when the value of the iframe's src changes.

So although the page corresponding to the URL of my code has changed, the URL has not changed, that is, the value of the src of the iframe has not changed. Therefore, the content is not refreshed;

Solution

Now that the cause is found, the solution is very easy. Just think of any way to change the value of the iframe's src.
My solution at the time was as follows:

$("#h5Content").attr("src","${h5.url}"+"?time="+new Date().getTime());

Pass the current time after the question mark to the URL and the problem is solved. This value has no other use except to change the value of src.

PS: Complete solution to the problem of iframe cache not refreshing

I encountered a very strange problem these two days. A page nested an iframe page. When this page was submitted and jumped to this page again, the page in the iframe should have refreshed the data, but it did not refresh under IE (no problem under FF). It must be refreshed manually by pressing F5 or opening a new browser tab. Otherwise, pressing Enter on the browser of this page is useless. After consulting a lot of information, I finally found that it was the iframe cache mechanism that was causing trouble. The following method can solve it:

<script type="text/javascript">
var randomnumber = Math.floor(Math.random()*100000)

document.write('
<iframe src="http://www.freedonation.com/hunger/hunger_thankyou.php3?random='+randomnumber+'" name="aframe" width="100%" height="400"></iframe>')

</script>

By adding a parameter with a random number as the request value, the browser considers that each requested page is new and ensures that the iframe page is reloaded each time.

This concludes this article on how to solve the problem when the content pointed to by the iframe's src does not refresh. For more information about the problem when the content pointed to by the iframe's src does not refresh, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  This article will help you understand JavaScript variables and data types

>>:  Ubuntu boot auto-start service settings

Recommend

Detailed explanation of Linux command unzip

Table of contents 1. unzip command 1.1 Syntax 1.2...

Detailed instructions for installing SuPHP on CentOS 7.2

By default, PHP on CentOS 7 runs as apache or nob...

Complete steps to use element in vue3.0

Preface: Use the element framework in vue3.0, bec...

About the problem of writing plugins for mounting DOM in vue3

Compared with vue2, vue3 has an additional concep...

Samba server configuration under Centos7 (actual combat)

Samba Overview Samba is a free software that impl...

How to use async and await in JS

Table of contents 1. async 2. await: 3. Comprehen...

$nextTick explanation that you can understand at a glance

Table of contents 1. Functional description 2. Pa...

Docker deployment RabbitMQ container implementation process analysis

1. Pull the image First, execute the following co...

An example of elegant writing of judgment in JavaScript

Table of contents Preface 1. Monadic Judgment 1.1...

How to implement image mapping with CSS

1. Introduction Image maps allow you to designate...

VMware vsphere 6.5 installation tutorial (picture and text)

vmware vsphere 6.5 is the classic version of vsph...

Example of using JSX to build component Parser development

Table of contents JSX environment construction Se...

Detailed process of configuring Https certificate under Nginx

1. The difference between Http and Https HTTP: It...