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

A small introduction to the use of position in HTML

I just learned some html yesterday, and I couldn&#...

Vue realizes adding watermark to uploaded pictures (upgraded version)

The vue project implements an upgraded version of...

Common rule priority issues of Nginx location

Table of contents 1. Location / Matching 2. Locat...

HTML table tag tutorial (21): row border color attribute BORDERCOLOR

To beautify the table, you can set different bord...

Nginx service 500: Internal Server Error one of the reasons

500 (Internal Server Error) The server encountere...

Two implementation solutions for vuex data persistence

Table of contents Business requirements: Solution...

Vue3.0 implements the magnifying glass effect case study

The effect to be achieved is: fixed zoom in twice...

Basic usage tutorial of MySQL slow query log

Slow query log related parameters MySQL slow quer...

Nginx tp3.2.3 404 problem solution

Recently I changed Apache to nginx. When I moved ...

Detailed tutorial on deploying apollo with docker

1. Introduction I won’t go into details about apo...

How to set static IP in centOS7 NET mode

Preface NAT forwarding: Simply put, NAT is the us...

js to achieve sliding carousel effect

This article shares the specific code of js to ac...

How to calculate the value of ken_len in MySQL query plan

The meaning of key_len In MySQL, you can use expl...

Why does MySQL paging become slower and slower when using limit?

Table of contents 1. Test experiment 2. Performan...