Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create an iframe with an empty src that's a standards compliant alternative to "#"

Tags:

html

I have an iframe on a page that I need to initially have a blank src for, as I eventually set the src with javascript.

I had been using a however have encountered an issue in Safari and Chrome where this loads a duplicate copy of my page within the iframe.

I read about "about:blank" in another question, however I've read that IE9 sends a null request to the server when you use this as the src. I've also yet to find anything listing this src as standards compliant.

Does anyone have an alternative to "about:blank" that they use to create an empty iframe?

like image 599
A.Wack Avatar asked Apr 04 '12 18:04

A.Wack


People also ask

How do I create an empty iframe?

about:blank is the way to do it. Alternately, you could just insert the whole <iframe> element with JavaScript later, and don't worry about a valid "empty" src . Yea upon testing in Firefox, Chrome, Safari and IE 7/8/9 "about:blank" seems to be the best solution.

What is a good alternative to iframe?

Use the embed Tag as an Alternative to Iframe in HTML The embed tag is similar to the object tag, and it is used for the same purpose. We can embed various external resources in our web page using the embed tag. We can embed media like PDF, image, audio, video, and web pages.

What is an iframe src?

The src attribute specifies the address of the document to embed in an iframe.

Can we use iframe in HTML5?

No, there isn't an equivalent. The <iframe> element is still valid in HTML5. Depending on what exact interaction you need there might be different APIs. For example there's the postMessage method which allows you to achieve cross domain javascript interaction.


2 Answers

about:blank is the way to do it. Alternately, you could just insert the whole <iframe> element with JavaScript later, and don't worry about a valid "empty" src.

like image 57
Matt Ball Avatar answered Oct 23 '22 23:10

Matt Ball


One of the linkers in Google Web Toolkit contains a dynamically created iframe. They use javascript:'' as a temporary placeholder for the src attribute. The reason, according to the source comments, is "Prevents mixed mode security in IE6/7.".

Source.

like image 39
Henrik Aasted Sørensen Avatar answered Oct 23 '22 23:10

Henrik Aasted Sørensen