Closed Bug 44285 Opened 24 years ago Closed 24 years ago

Can't LINK stylesheets from JS

Categories

(Core :: CSS Parsing and Computation, defect, P3)

defect

Tracking

()

VERIFIED FIXED

People

(Reporter: mech_filter, Assigned: pierre)

References

()

Details

(Whiteboard: [nsbeta3+][Fix in hand])

Attachments

(8 files)

From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Mac_PowerPC)
BuildID:    2000062914

I'm not 100% certain that this is a true bug. Filing in browser-General until
we know whether this is a javascript problem, or an HTTP problem or what. 

At any rate, what's happening is my page has a javascript up near the top that
tries to detect your platform, and assign a platform-specific stylesheet.  It
specifies a generic/default/unix version just before the script, and then
overrides this with a javascript for Mac or Win users.  Actually it's not quite that
smart. Basically, if you are using a Mac, you get the Mac one. If you are using any
other platform AND you have javascript enabled, you get the "Windows" version
(so some Unix users will get that one), and if you have no javascript support
(turned on) you get the "unix" version, regardless of platform.  At any rate, Mozilla
is either only loading the unix version (not interpreting the script at all), or  is not
identifying my machine as a Mac.  The script just looks for "mac" substring.  Or, I
suppose it is possible it is IDing the machine correctly, but not following the
cascade properly, and not letting the 2nd .css override the 1st.

If the script is mangled in some way, please let me know.  For that matter, if
anyone knows how to make it smarter and actually assign the Windows .css file
to Windows only, that'd be very cool. (I didn't write the script, I just got it from
somewhere else).


Reproducible: Always
Steps to Reproduce:
1. Just load the test page.


Actual Results:  Browser is using the first-specified, generic stylesheet.

Expected Results:  Should be using the Mac stylesheet.

PS: If you need to look at the stylesheets, and your browser will not let you
load a .css file into a window as a text file (there are some with this problem),
all the stylesheets have symlinks to them with .txt extensions appended.  E.g.
 http://www.eff.org/stylesheets/effstyle-mac.css
also exists as
 http://www.eff.org/stylesheets/effstyle-mac.css.txt

Toodles...
It seems to me that its your JS that's flawed, not Mozilla. You link to the
stylesheet first and then use the javascript to put in another link.

EXAMPLE:

<LINK TO UNIX STYLE SHEET>
<script>
if mac: write <LINK TO MAC STYLE SHEET>
</script>

End result:

<LINK TO UNIX STYLE SHEET>
<LINK TO MAC STYLE SHEET>

I think that the browser is seing the unix link and because it is first, using
that instead of the mac one. Maybe you should include all the platforms in the
javascript because any browser that doesn't support javascript doesn't support
style sheets.

Then again, I could be completely wrong on this.
Resolving INVALID.  I will post a modified version of the page.  I have added 2 

alerts, which are right after the mac and win stylesheet assignments.  Mozilla 

will pop up the Mac Stylesheet Alert, as it is supposed to.



HOWEVER,

The navigator.platform gives me "MacPPC" on Netscape 4, but "Macintosh" on 

Mozilla.  Is this supposed to be the case?



Note:

To detect if the comp is running Windows, you can search for "Win" just as you 

search for "Mac," I think.

Status: UNCONFIRMED → RESOLVED
Closed: 24 years ago
Resolution: --- → INVALID
Attached file modified test file
qaz2@usa.net 
>Resolving INVALID.  I will post a modified version of the page.  I have added 2 
>alerts, which are right after the mac and win stylesheet assignments.  Mozilla 
>will pop up the Mac Stylesheet Alert, as it is supposed to.

Nifty test, but it *doesn't* make the bug invalid. Here's why.  Regardless what part of
the script is triggered by Mozilla, and what stylesheets it is or isn't actually loading and 
parsing, the styles that are *applied* are those from effstyle-unix.css.  I tested and
verified this by changing .menu and .MENU at bottom of stylesheet to a huge ugly
14pt in effstyle-mac.css, reloaded, saw no change, did the same with effstyle-win.css
(no change), and finally with effstyle-unix.css, and this time the left-side menu font 
turned to 14pt on reload.

This would appear to conclusively demonstrate a rather serious CSS cascading bug.

Probably bears setting up some javascriptless tests that do nothing but load 2+
.css files in <HEAD>, in series, to mark up some simple demo content, to see if it always 
ignores a second or later .css file that overrides the values of the first, or is only doing it 
under particular circumstances.

>The navigator.platform gives me "MacPPC" on Netscape 4, but "Macintosh" on 
>Mozilla.  Is this supposed to be the case?

Dunno. I suspect that how the platform is determined and reported isn't standardized. 
Either string should match "Mac", though, so I personally don't care. :-)

>To detect if the comp is running Windows, you can search for "Win" just as you 
>search for "Mac," I think.

Well, I figured that.  I guess what I was getting at is that I'm too Javascript-stupid to 
actually know how to re-write the script with another loop to do that. I don't know js at 
all, I just got this script from a friend.   Ideally it'd say "If Mac, use effstyle-mac.css. If 
Win, juse effstyle-win.css. If anything else, use effstyle-unix.css. And if no js is enabled, 
use effstyle-unix.css by default", please pardon my incredibly wretched pseudocode.



zach@zachlipton.com wrote:
>It seems to me that its your JS that's flawed, not Mozilla. You link to the
>stylesheet first and then use the javascript to put in another link.
[...]
>I think that the browser is seing the unix link and because it is first, using
>that instead of the mac one.

If this is the case, then this is certainly a bug. CSS is called *cascading*
stylesheets for a reason.  :-)   Namely, any stylesheet is overriden by subsquently 
parsed stylesheets or CLASS instances.  This is precisely why the generic .css is loaded
first, such that only systems that trigger the custom .css files will load them, and any
browsers with js turned off will still load at least the generic stylesheet. 'Zilla
doesn't appear to be loading (or at least not properly cascading) either of the custom
variants (despite qaz2@usa.net's proof that it is parsing the script correctly), just 
sticking with the generic one that it hit first.

>Maybe you should include all the platforms in the javascript because any
> browser that doesn't support javascript doesn't support style sheets.

I don't see why that would necessarily be true, though it might be incidentally
true in current browser deployment.  Doesn't matter anyway - many people turn off
the js support their browser has, but leave CSS enabled (though I find this doesn't
work in NS 4.x Win - if you turn of js, CSS dies too. "Oops".)
Severity: normal → major
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
over to style system.
Assignee: asa → pierre
Status: UNCONFIRMED → NEW
Component: Browser-General → Style System
Ever confirmed: true
QA Contact: doronr → ckritzer
The problem is that the secondary stylesheet, the one LINK'd by the script, is 
never getting loaded. In viewer, if you dump the stylesheets, you will see that 
the unix style sheet is loaded by the observing the console-output:
   CSS Style Sheet: http://www.eff.org/stylesheets/effstyle-unix.css 
and then a list of all of the rules in that sheet, however there is no ouptut to 
indicate that CSS Style Sheet: http://www.eff.org/stylesheets/effstyle-win.css 
has loaded (also there is no indication that the load was even attempted).

My guess is that the interaction between the Parser and the scripting engine is 
flawed and that the LINK that the script is writing is not getting processed 
correctly. I will attach a much smaller testcase that will allow us to debug the 
script-execution and subsequent LINK statement more easily.
CC'ing Harish since he has dealt with these parser/script/css-loader issues 
before.
Changed the summary from "Mac 'zilla not appearing as "mac" in platform test 
(js)" to "Can't LINK stylesheets from JS".
Summary: Mac 'zilla not appearing as "mac" in platform test (js) → Can't LINK stylesheets from JS
Attached file better testcase
The stylesheet which is LINKed by script is indeed loaded in 
CSSLoaderImpl::LoadStyleLink() and parsed in CSSLoaderImpl::ParseSheet() but 
obviously, it doesn't end up in the right place because, as Marc noticed, it 
doesn't appear in the document when we do Dump Stylesheets in Viewer.

So I played with document.write() a bit and I found a regression: when a DOCTYPE 
is specified, document.write() doesn't seem to work at all. I built a testcase 
based on htmlparser/tests/html/40143.html. This regression, like another one I 
found today, occured between 06/28 and 06/30. 

Reassigned to Parser/harishd to fix the regression with document.write() and then 
look into the problem with LINKed stylesheets.
Assignee: pierre → harishd
Component: Style System → Parser
The problem with the LINKed stylesheet could be a dup of bug 41637. I'm going to 
ask the folks there what they think. We still have the regression with 
document.write()...
Please refer to the patch in bug 44759.
Status: NEW → ASSIGNED
Attached patch Proposed patch.Splinter Review
Keywords: nsbeta3
Whiteboard: Fix in hand
Simple fix.  Marking nsbeta3+.
Whiteboard: Fix in hand → [nsbeta3+]Fix in hand
Whiteboard: [nsbeta3+]Fix in hand → [nsbeta3+][Fix in hand]
Fix is in. Marking FIXED.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago24 years ago
Resolution: --- → FIXED
I've checked this out on:
- LinuxRH62 2000-09-07-08-M18 Commercial
- Win98     2000-09-07-08-M18 Mozilla
- MacOS86   2000-09-07-04-M18 Commercial
And it doesn't seem to be working for any of them....

Reopening.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Okay, the document.write problem is definitely fixed. However, I think, the 
problem with linked style sheet exists. Per Pierre's comment ( 2000-07-19 03:19 
) reassigning this bug to him.
Assignee: harishd → pierre
Status: REOPENED → NEW
CCing Mark and myself to the bug.
IMPORTANT: Stanton McCandlish, I'm closing this bug as fixed again but an action 
is required from your side to fix the page at http://www.eff.org/test.

The thing that happens is the following... Since the LINKed stylesheets have a 
TITLE, they become selectable by the user under "View | Use Stylesheet" and the 
first one is selected by default ("EFF Unix/Generic Stylesheet"). In order to 
select the right default stylesheet, you need to add:

document.write('<META HTTP-EQUIV="default-style" CONTENT="EFF Mac Stylesheet">');

before linking the Mac stylesheet with document.write('<LINK REL=
"stylesheet"...). A similar fix should be done for the Win/PC stylesheet, of 
course.

More info about LINKed stylesheet can be found on
http://www.w3.org/TR/REC-html40/present/styles.html#h-14.3.1
Status: NEW → RESOLVED
Closed: 24 years ago24 years ago
Component: Parser → Style System
Resolution: --- → FIXED
Ian, would you mind having a bash at this one?  Thanks dude!
QA Contact: ckritzer → ianh
VERIFIED FIXED on Windows 2000 Commercial Build 2000091805 and RedHat Linux 6.2 
Commercial Build 2000091806 using simple test case created.

Note that original page provided does not work as expected because of the 
previously mentioned error on the page. (You need to add the 'preferred 
stylesheet' selection or swap the order of the stylesheets.)
Status: RESOLVED → VERIFIED
OS: All
Hardware: Macintosh → All
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: