I make webpage with iframe that displays the parent webpage
but it only can do it about 10 times
is there a way to make it infinite or control the exact precise number of recursions?

Dani AI

Generated

Short version: this is expected browser behavior. The HTML frame spec rejects infinite self-embedding — any frame that tries to use a URL already used by one of its ancestors is treated as if it had no SRC (it renders blank). See the W3C guidance on frame recursion for the specification explanation. W3C Implementing HTML Frames. (w3.org)

That explains the blank level you see rather than an endless stack. Implementations vary (engines and versions differ in exactly how many levels they show or whether they fail silently), and some browsers historically behaved differently when scripts forced navigation. If the goal is a long chain of nested pages for testing/demos, a common workaround is to give each iframe a unique URL (for example append a changing query string so each level is a distinct address). Experimental writeups show this approach and its limits. (bryanbraun.com)

Troubleshooting notes that complement ’s DevTools suggestion and ’s resource-warning: check the Network panel for each iframe request, and inspect response headers. A page can be refused silently if the server sends X-Frame-Options or a CSP frame-ancestors policy that blocks the embedding chain — those headers will stop rendering even when the console shows no error. See MDN on frame-ancestors and X-Frame-Options. (developer.mozilla.org)

If experimentation is needed, generate distinct URLs server-side or with a tiny script so each nested frame points to a unique URI. Example pattern (client-side): create an iframe, set its src to the current path plus ?n=<next>, and append it to the document. Keep in mind this eats memory and tabs can crash; for production use avoid deep nesting and prefer controlled alternatives (single iframe + dynamic content, srcdoc, or server-generated pages).

Recommended Answers

All 5 Replies

but it only can do it about 10 times

What happens after the 10th time? I dont understand what you mean. Can you provide more information about the problem?

The 10th iframe is empty.

I've never experienced that behavior with a frame within a page. The content within the frame is managed by the source so if you are getting a blank page, there is something on that end preventing the data from coming over to the browser.

In your browser's tools (F12), is there any indication of errors or other messages in the console?

Do you have access to the content or code that produces the markup in the iframe?

the console does not give any feedback for the subject matter
the iframe is self referential
so its source is the address to its own page
I just have index.html with this code in the body

<IFRAME SRC="/~mahrud/inception">the never ending iframe</IFRAME>

A recursive IFrame can cause a system to run out of resources if left unchecked. I wouldn't be surprised if you've discovered a hard limit in the browser, intended to prevent this kind of thing from happening. Have you tested to see whether the limit is browser specific?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.