Mr. Alien
Mr. Alien

Reputation: 157334

Using meta refresh tag in the iframe source page causes the page to refresh where iframe has being called

I was finding a quick way for a simple chat page, as I don't want to use Ajax or jQuery so I used the below tag on the source page like for example page2.php

<meta http-equiv="refresh" content="2">
<!--And the page content goes here-->

And I used this on page1.php

<iframe src="page2.php" border="1"></iframe>

Now what I expected was only iframe to be refreshed but the the whole page1.php is refreshed, why that so? Than what's the use of declaring meta refresh on page2.php? Does actually using iframe embeds the markup of the source page in the page where we are using the iframe?

Upvotes: 3

Views: 4218

Answers (1)

johnmadrak
johnmadrak

Reputation: 825

Unfortunately, it looks like because of the way the iframe is loaded there is no way around this issue. The iframe must be loaded into the DOM in order for it to work, and once it has been it appears the meta refresh is affecting the page as a whole.

Instead, you can use the following onLoad [or, if you're using jQuery in $(document).ready()]:

setInterval(function(){ 
                        window.frames['someLogicalName'].location.reload();
            },2000);

And then adjust your iframe:

<iframe src="page2.php" name="someLogicalName" border="1"></iframe>

Upvotes: 1

Related Questions