Closed Bug 83981 Opened 24 years ago Closed 24 years ago

document.getElementById([link]).href = [url]; doesn't respond

Categories

(Core :: DOM: CSS Object Model, defect, P3)

x86
Windows NT
defect

Tracking

()

RESOLVED FIXED
mozilla0.9.4

People

(Reporter: martin.hofer, Assigned: jst)

References

()

Details

Attachments

(2 files)

From Bugzilla Helper: User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; 0.8) Gecko/20010215 BuildID: 2001021508 I have a web page that ist formatted by a .css file. Now I am trying to assign an new "skin" to the page by setting the href of the link to the .css file: document.getElementById('csslink').href = 'test.css'; This works (I know because document.getElementById('sty').href is set correctly to the new file name, automatically extended by the complete path), but there are no visible results. Even forcing the browser to re-render the page by assigning new styles to elements of the page doesn't help. Reproducible: Always Steps to Reproduce: I have prepared a page to demonstrate the problem: 1. Go to http://www.internetfabrik.de/martin/mozillabug/test.html 2. Click on the link 'test'. Try it with IE 5.5 (5.0 won't work either), it works there (via document.all of course) Actual Results: The page doesn't change. Expected Results: The page should change, according to the new style sheet. I'm not sure if this meets your definition of a bug, but I think if it is possible to set this value, there should be a result ;-) If you don't want this to be possible, you should consider making this variable read-only.
In a debug Mozilla build, I see this error when I perform the test: Error loading URL javascript:test() : 2152924149 I don't know if that is relevant or not. This is a browser issue, not JavaScript Engine. Reassigning to Style System component for further triage; not sure if this is a duplicate of an existing bug - Here is the HTML of the testcase: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>Unbenannt</title> <link rel=stylesheet type="text/css" href="formats.css" ID="csslink"> <SCRIPT LANGUAGE="JAVASCRIPT"> function test() { if (document.all) { document.all.sty.href = 'test.css'; } else if (document.getElementById) { alert('BEFORE:\ndocument.getElementById(\'csslink\').href is now\n' + document.getElementById('csslink').href) alert('ACTION:\nsetting document.getElementById(\'csslink\').href to \'test.css\'\n') document.getElementById('csslink').href = 'test.css'; alert('AFTER:\ndocument.getElementById(\'csslink\').href has been changed to\n' + document.getElementById('csslink').href + '\nbut the page didn\'t change!') } } </SCRIPT> </head> <body ID="b"> <A HREF="javascript:test()">test</A> </body> </html>
Assignee: rogerl → pierre
Status: UNCONFIRMED → NEW
Component: Javascript Engine → Style System
Ever confirmed: true
QA Contact: pschwartau → ian
This looks really familiar. I'm almost certain it's a dup.
Whiteboard: DUPEME
Martin, please try my version.
For reference, here is H-J's HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>sm83981-0.html</title> <link rel=stylesheet type="text/css" href="http://www.internetfabrik.de/martin/mozillabug/formats.css" ID="csslink"> <script type="application/x-javascript"> <!-- function test() { document.getElementById('csslink').setAttribute("href","http://www.internetfabri k.de/martin/mozillabug/test.css"); } //--> </script> </head> <body ID="b"> <a HREF="javascript:test()">test</a> </body> </html>
Assignee: pierre → peterv
Component: Style System → DOM Style
Whiteboard: DUPEME
Dynamic changes of linked stylesheets was implemented by peterv in bug 7515 but I'm not marking this bug as dup yet because we need to answer the following question... This line works: document.getElementById('csslink').setAttribute("href","test.css"); This line does not work: document.getElementById('csslink').href = 'test.css'; Is it normal?
martin.hofer: note that your build (2001021508) doesn't have the fix for bug 7515 which was checked in on May 18th.
I have a patch, I'll attach it later today.
Status: NEW → ASSIGNED
Priority: -- → P3
Target Milestone: --- → mozilla0.9.4
The fix seems to be in contradiction with the comment on line #93 which says: "nsGenericHTMLLeafElement::SetAttribute() calls SetAttribute() which ends up calling UpdateStyleSheet so we don't call UpdateStyleSheet here ourselves." If the comment is wrong or doesn't apply to the proposed fix, then r=pierre.
Well, we have too many SetAttribute functions ;). nsGenericHTMLLeafElement::SetAttribute(nsINodeInfo* aNodeInfo, ...) calls nsHTMLLinkElement::SetAttribute(PRInt32 aNameSpaceID, ...) which calls UpdateStyleSheet(). This function calls nsGenericHTMLLeafElement::SetAttribute(PRInt32 aNameSpaceID, ...), not nsHTMLLinkElement::SetAttribute(PRInt32 aNameSpaceID, ...). Are you confused yet? I could change the comment to // nsGenericHTMLLeafElement::SetAttribute(nsINodeInfo* aNodeInfo, // const nsAReadableString& aValue, // PRBool aNotify) // // calls // // nsHTMLLinkElement::SetAttribute(PRInt32 aNameSpaceID, // nsIAtom* aName, // const nsAReadableString& aValue, // PRBool aNotify) // // which ends up calling UpdateStyleSheet so we don't call UpdateStyleSheet // here ourselves.
r=pierre with updated comment. jst, please s/r
sr=jst
Checked in.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
I don't see the testcase working at all with build 2001081716 on Win2k (SP2). It works just fine with IE 5.5 (SP1). However, the link given in the URL works just fine. Here's the difference: The link in the URL field uses (works): document.getElementById('csslink').href='http://www.internetfabrik.de/martin/mozillabug/test.css'; The testcase uses (dosn't work): document.getElementById('csslink').setAttribute('href','http://www.internetfabrik.de/martin/mozillabug/test.css'); Note: This seems to be exactly opposite of the behavior that Pierre noted in his 7/20 comment. Reopening this bug for the problem with setAttribute not working any more. Jake
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Fall-out from the SetAttribute/SetAttr renaming. Jst wants this.
Assignee: peterv → jst
Status: REOPENED → NEW
..and fixed it.
Status: NEW → RESOLVED
Closed: 24 years ago24 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: