473,385 Members | 2,029 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,385 software developers and data experts.

<!DOCTYPE> breaking a script?

I have reason for an element on a page to be static, like the CSS property
"position: fixed" defines.

Obviously, this CSS property doesn't work in IE :-/

I have looked around at alternatives, and found one that suits my needs, an
active Javascript that changes the position of the element when the page is
scrolled.

A simple test implementation of the script can be seen at
http://evil.mooo.com/test.html. It works perfectly.

When I add a <!DOCTYPE> declaration to the top of the page, so it conforms
with W3C's standards, the script breaks, and I get this
http://evil.mooo.com/test2.html.

What is happening? Any ideas?
Jul 23 '05 #1
8 1559
On Mon, 04 Oct 2004 15:11:13 GMT, Matthew Schubert wrote:
I have reason for an element on a page to be static, like the CSS property
"position: fixed" defines. Obviously, this CSS property doesn't work in IE :-/
Exactly.
I have looked around at alternatives, and found one that suits my needs, an
active Javascript that changes the position of the element when the page is
scrolled.
This is old school method. Use expression instead (IE5+)
When I add a <!DOCTYPE> declaration to the top of the page, so it conforms
with W3C's standards, the script breaks, and I get this
http://evil.mooo.com/test2.html. What is happening? Any ideas?


Replacing document.body with document.documentElement.

You can check the document.compatMode for choose body or documentElement.

--
ZER0://coder.gfxer.web-designer/

~ Come devo regolare la stampante laser per stordire?
(How do I set a laser printer to stun?)

on air ~ "Yellowcard - Breathing"
Jul 23 '05 #2
On Mon, 04 Oct 2004 15:11:13 GMT, Matthew Schubert
<sa***@addstylecleaning.com> wrote:
I have reason for an element on a page to be static, like the CSS
property "position: fixed" defines.

Obviously, this CSS property doesn't work in IE :-/
Someone asked for something similar recently in this thread:

<URL:http://groups.google.com/groups?threadm=1319c3c8.0409281107.1b34b642%40post ing.google.com>

Though in my final solution, the fixed content was centred. It's easy
enough to adjust, though. Ask if you need help.
I have looked around at alternatives, and found one that suits my needs,
an active Javascript that changes the position of the element when the
page is scrolled.
I must say, it's a horrible implementation. Browser detection should
always be avoided with feature detection used in its place. In this case,
I used Microsoft's conditional comments, the contents of which change the
position property to absolute and add a script which moves the box when
the page is scrolled.
A simple test implementation of the script can be seen at
http://evil.mooo.com/test.html. It works perfectly.

When I add a <!DOCTYPE> declaration to the top of the page, so it
conforms with W3C's standards, the script breaks, and I get this
http://evil.mooo.com/test2.html.

What is happening? Any ideas?


The problem you're seeing is that when a DOCTYPE is specified, IE, like
most browsers, switches into strict mode. When IE does this, it uses
document.documentElement, not document.body, to hold the clientWidth, and
similar, properties. The code I've presented adapts as necessary[1].

Hope that helps,
Mike
[1] Many thanks to Richard Cornford for the concept, or at least an
implementation of it.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
> This is old school method. Use expression instead (IE5+)

Eh?
Replacing document.body with document.documentElement.


Tried. Failed (At least in Firefox).
Jul 23 '05 #4
On Mon, 04 Oct 2004 15:28:20 GMT, Matthew Schubert wrote:
This is old school method. Use expression instead (IE5+)
Eh?
http://msdn.microsoft.com/workshop/a...iew/recalc.asp

Of course, expressions are not a w3c standard. But fix a lot of stuff in
IE.
You can use position:fixed for the browsers w3c compliant; and expression
for emulate it in IE.
Replacing document.body with document.documentElement.

Tried. Failed (At least in Firefox).


I'm talking about IE. In IE it works. In Firefox it doesn't works 'cause
you missed the "px" suffix in your measures.

--
ZER0://coder.gfxer.web-designer/

~ Io non soffro di pazzia, ne godo ogni minuto.
(I don't suffer from insanity, I enjoy every minute of it)

on air ~ "Donots - Saccharine Smiles"
Jul 23 '05 #5
Why is the second <script> outside of the IE conditional comments?

Is it not required only by IE in this case? (Remember I do not need the
button to make the DIV visible).

It is a nice implementation. One thing though. I do not like the way it
"jerks" when scrolling. The original script I posted smoothly scrolled the
DIV...

Also, I tried replacing document.body with document.documentElement, and it
works perfectly in IE, but not in Firefox :-/

I think I will use your script, with a little modification :-) Thanks a
bunch.
Jul 23 '05 #6
On Mon, 04 Oct 2004 15:50:27 GMT, Matthew Schubert
<sa***@addstylecleaning.com> wrote:
Why is the second <script> outside of the IE conditional comments?

Is it not required only by IE in this case? (Remember I do not need the
button to make the DIV visible).
The code there, part of a larger collection, is used in both the IE code
and the showWait function, used to make the DIV appear.
It is a nice implementation. One thing though. I do not like the way it
"jerks" when scrolling. The original script I posted smoothly scrolled
the DIV...
It was a quick fix. I woke up that morning and the first thing that came
to my mind was: "If the user scrolls the page, the DIV will shift." Odd, I
know. As I hadn't had anything back from the OP, I thought I should just
add the extra code as soon as possible. I should have just tested though
about it more in the first place.

If you want smoother movement, I could add it if you want.
Also, I tried replacing document.body with document.documentElement, and
it works perfectly in IE, but not in Firefox :-/
Firefox doesn't report properties like scrollTop on the HTML element
(which is what documentElement refers to). However, as Firefox does
support the fixed position value, there isn't much point in worrying about
that.
I think I will use your script, with a little modification :-) Thanks a
bunch.


You're welcome.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #7
Matthew Schubert wrote:
I have reason for an element on a page to be static, like the CSS
property "position: fixed" defines.

Obviously, this CSS property doesn't work in IE :-/

I have looked around at alternatives, and found one that suits my
needs, an active Javascript that changes the position of the element
when the page is scrolled.


Have a look at IE7: http://dean.edwards.name/IE7/compatibility/fixed.html
Jul 23 '05 #8
Duncan Booth wrote:

Have a look at IE7: http://dean.edwards.name/IE7/compatibility/fixed.html


http://dean.edwards.name/IE7/ie7-standard-p.js

interesting source...

Mick
Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
3
by: | last post by:
I have been researching articles on google on how to create a simple RSS feed that sucks <title><blurb><link><date> out of a sql server 2000 database via an aspx page. I know it has to be pushed...
44
by: rhythmace | last post by:
W3C HTML validator passes this: .... <script type="text/javascript" src="foo.js"> <script type="text/javascript"> ....script in here... </script> ....
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
2
by: -Karl | last post by:
Couls someone please advise me on this error. What I am trying to do is be able to convert an XML document into arrays. I read that the subs & functions have to be in <scripttags. Thanks! ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.