473,322 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Issue with firefox and inline document.write

I am trying the following code in FireFox 3.6
-- code --
<script type="text/javascript">
document.write('<a href="javascript:t()" >');
</script>
<div id="rt2"> Click2 </div>
</a>

--- FireFOx DOM --

<a href="javascript:t()"></a>
<div id="rt2">
<a href="javascript:t()"> Click2 </a>
</div>

----- END ---
This seem to be completely messed up. All other browsers (IE 8, Safari ) are rendering it properly.

---- OTHER Browsers --
<a href="javascript:t()">
<div id="rt2"> Click2 </div>
</a>
--- END ----

Appreciate any insight.
Sep 1 '10 #1
8 1869
johny10151981
1,059 1GB
It work fine with firefox 3.6.8 and IE8.

What is your actual problem?
Sep 1 '10 #2
You can click the link but the issue is with the actual DOM elements. Please install Firebug and click on the HTML tab. Observe how the <a> and <div> tags are inside out. You may have to use DOM inspector on IE to see the same.
Sep 1 '10 #3
kovik
1,044 Expert 1GB
Basically, your anchor tag is still open. By HTML standards, block elements cannot be rendered within inline elements. So, browsers can either forcefully end your anchor tag, or, like Firefox does, continue into the block element.

Basically, use proper markup if you want consistency. There are no standards for broken HTML, so there's no such thing as rendering your broken HTML "properly."
Sep 1 '10 #4
I can understand FF closing the anchor tag. But with FF I end up with two anchor tags, one inside and one outside the div.

<a href="javascript:t()"></a> <-- 1
<div id="rt2">
<a href="javascript:t()"> Click2 </a> <--- 2
</div>
Sep 1 '10 #5
kovik
1,044 Expert 1GB
I don't think you are following.

The <div> element CANNOT be inside of the <a> element. Firefox will have <a> tags around EVERYTHING that comes after that element to mimic your broken HTML. The source that you are viewing is not the ACTUAL source of the website. It is the source that Firefox generates from your source.

The reasons browsers have to generate their own source which can differ from the actual code is because they can't simply deny pages with malformed HTML. They have to serve those pages, somehow.


Now fix the damned tag. :P
Sep 2 '10 #6
Thank you for the response. That was just a simplified piece of code extract from an enterprise app. The source am referring to is the generated source by firefox (using the DOM viewer in firebug).

I do have a follow upp question.

Why Firefox render
<a href="javascript:t()"><div> Click </div> </a> properly but not the inline script version ? In this case the inline element <a> is not fragmented or duplicated. I understood that both are broken HTML but the rendering (DOM) is different.
Sep 2 '10 #7
kovik
1,044 Expert 1GB
Attempting to explain why browsers handle malformed HTML differently is pointless. Like I said, there's no standard and they can handle it however they want. If you are really curious, take it up with Mozilla. :P
Sep 2 '10 #8
Actually I did post the question. For the work am doing, understanding the html parser is necessary. Unfortunately the parser for the same browser itself is behaving differently. I will update if I hear anything back from Mozilla.
Sep 2 '10 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Eli | last post by:
I've got a script that I'm trying to debug which uses document.write() to place HTML within a page. In both IE6 and Firefox when I view source, I see only the script itself and not any HTML as...
7
by: Remi Bastide | last post by:
I'm trying to open a blank window and write a message in it. The following page works as expected in IE, but in Firefox the message is not written: <HTML> <HEAD> <TITLE>Document.write...
5
by: s_m_b | last post by:
function saveState() { document.write (" | <a href = 'myhomepage.asp? view=mhp&amp;action=save&amp;pb="); >> document.write (document.phone.style.display.value); document.write ("'>save view</a>"); };...
7
by: Ignac Vucko | last post by:
Is writing a document *during* page load safe and supported for all 4th and 5th generation browsers? If not, can you show me a specific example/browser where it causes problems? <html> <head>...
2
by: robert.waters | last post by:
Hello, I am dynamically editing the contents of a page and using document.write() to reload the new, edited content. However, on the new page, any calls to functions located in external .js...
11
by: Michael Powe | last post by:
How can I make an XHTML-compliant form of an expression in this format: document.write("<scr"+"ipt type='text/javascript' src='path/to/file.js'>"+"</scr"+"ipt>"); this turns out to be a...
5
by: SuneR | last post by:
Hi, I am having problems figuring out how to make Firefox behave, and output the HTML I want it to output. The thing I want done is actually quite simple. I have a <labeltag, and inside it, I...
7
by: sj071 | last post by:
I'm little more than a novice when it comes to javascript, and this particular problem has been driving me mad for the past few days... The Problem: I have a javascript file that uses...
1
by: celeroSolutions | last post by:
This code works in my site in IE, but not in FireFox, and I'm stuck as to why! Any ideas? (The image paths are correct, I've tested these.) <script language="javascript" type="text/javascript">...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.