Printable Version of Topic

Click here to view this topic in its original format

HTMLHelp Forums _ Markup (HTML, XHTML, XML) _ Iframe and the browsers back button

Posted by: nyhetsgrupper Jan 17 2010, 02:11 AM

I have this simple html page:

CODE

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <h1>Header</h1>
    <iframe id="myIframe" src="http://www.amazon.com/" style="width:100%; height:500px"/>
</html>


As you can see I load amazon.com into an iframe (but this has nothing to do with amazon.com, it applies for any site). If I click on a link at the web site loaded in the iframe the browser back button gets enabled. If I click the back button I would expect the iframe to go back to the last visited page, and leave my hosting page (the page containing the header and the iframe) untouched. This is also what happens in Chrome, but in IE8 it replaces the complete page with amazon.com (and my header and Iframe is then gone). Is this a bug in IE? Can I get it to behave like I want?

Posted by: Christian J Jan 17 2010, 06:14 AM

I get no back button at all in IE8. unsure.gif

BTW, here's an example of a "minimal" XHTML document: http://www.w3.org/Consortium/Offices/Presentations/XHTML/4.html --note the explicit HEAD and BODY elements (the W3C example uses a Strict Doctype which doesn't permit iframes, so you should stick with your transitional Doctype). In HTML4 the HTML, HEAD and BODY element tags are optional (TITLE is mandatory, though).

BTW 2, it seems the end tag for the IFRAME really can be replaced with an ending slash in the start tag, is that valid XHTML (tested in WDG and W3C validators)? unsure.gif



Posted by: Brian Chandler Jan 17 2010, 07:29 AM

QUOTE
BTW 2, it seems the end tag for the IFRAME really can be replaced with an ending slash in the start tag, is that valid XHTML (tested in WDG and W3C validators)?


IIUTQC, I think so. All tags must be closed, but you are allowed to replace a content free one like

<MOLLUSC></MOLLUSC>

by (the to me immensely ugly)

<MOLLUSC />

Isn't that it? I might have quite misunderstood the question. Oh, I mean, IMHQMTQ.

Posted by: Christian J Jan 17 2010, 09:20 AM

QUOTE(Brian Chandler @ Jan 17 2010, 01:29 PM) *

QUOTE
BTW 2, it seems the end tag for the IFRAME really can be replaced with an ending slash in the start tag, is that valid XHTML (tested in WDG and W3C validators)?


IIUTQC, I think so. All tags must be closed, but you are allowed to replace a content free one like

<MOLLUSC></MOLLUSC>

by (the to me immensely ugly)

<MOLLUSC />

Isn't that it? I might have quite misunderstood the question.

No, that's what I was asking.

QUOTE
Oh, I mean, IMHQMTQ.

IMHMTQ? wacko.gif

Posted by: nyhetsgrupper Jan 17 2010, 02:36 PM

I changed the html a litle, to make it validate:

CODE

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

<title>Test page</title>

<style type="text/css">
iframe.c1 {width:100%; height:500px}
</style>
</head>
<body>
<div>
<h1>Header</h1>
<iframe id="myIframe" src="http://www.amazon.com/" class="c1" name="myIframe"></iframe></div>
</body>
</html>



The result is exactly the same. When I click on what ever link in the amazon.com page showing in the iframe the browser back button is enabled, and if i press back amazon.com is replacing my page (not showing my header and iframe anymore).

Posted by: pandy Jan 17 2010, 06:21 PM

It isn't right to slash it when a closing tag exists. IFRAME isn't empty BTW. That's why it has a closing tag.

The choice between closing tag and slash only exists for real empty elements that have no closing tag in HTML. Adding a closing tag to those isn't compatible with all browsers so that leaves us with the ugly slash anyway.

Posted by: Christian J Jan 17 2010, 08:03 PM

QUOTE(nyhetsgrupper @ Jan 17 2010, 08:36 PM) *

The result is exactly the same. When I click on what ever link in the amazon.com page showing in the iframe the browser back button is enabled, and if i press back amazon.com is replacing my page (not showing my header and iframe anymore).

Seems to be something strange with amazon.com, when I disabled javascript in IE8 I got a functional Back button. Framing other sites works fine even with javascript.

Posted by: Christian J Jan 17 2010, 08:07 PM

QUOTE(pandy @ Jan 18 2010, 12:21 AM) *

It isn't right to slash it when a closing tag exists. IFRAME isn't empty BTW. That's why it has a closing tag.

You mean right as in valid? The validators don't complain for some reason, that's why I'm puzzled. unsure.gif

QUOTE
The choice between closing tag and slash only exists for real empty elements that have no closing tag in HTML. Adding a closing tag to those isn't compatible with all browsers so that leaves us with the ugly slash anyway.

That's what I thought too.

Posted by: pandy Jan 17 2010, 10:45 PM

I don't know what's up with that.

Go validate this.

CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
  
<h1 />
<blockquote />
<p />

</body>
</html>

Posted by: Darin McGrew Jan 18 2010, 03:42 AM

Yeah, basically, the XHTML validator doesn't know the difference between elements that should be empty like <br /> and <img />, and elements that shouldn't be empty like <h1 /> and <blockquote /> and <p /> and <iframe />.

Posted by: pandy Jan 18 2010, 03:58 AM

Oh dear. I suspected that but didn't dare to say it. tongue.gif

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)