MediaWiki talk:Common.js/Archive 11: Difference between revisions

Content deleted Content added
Shadowbot3 (talk | contribs)
m Automated archival of 1 sections from MediaWiki talk:Common.js
 
Shadowbot3 (talk | contribs)
m Automated archival of 1 sections from MediaWiki talk:Common.js
Line 16:
 
::::::They probably shouldn't thow up on the print version. They aren't useful on paper, and the footer should cover the donation notice stuff. --[[User_talk:Gmaxwell|Gmaxwell]][[Image:Tromboon-sample.ogg|100px|noicon]] 17:45, 1 October 2007 (UTC)
<span id="63316408846" />
== Problem with importStylesheet in IE? ==
 
Is anyone else having an problem with importStylesheet in Internet Explorer? I am using Internet Explorer 6, and it's giving me a JS error. The error information I get from IE is the following:
* Line: 58
* Char: 6
* Error: Unexpected call to method or property access.
* Code: 0
* URL: (Whatever the address in your browser is)
To recreate the error, open IE and edit your <s>skin css file</s> javascript file <small>'' (fixed by [[User:Alex Smotrov|Alex Smotrov]])''</small>. At the bottom of the file put the line <code>importStylesheet( "User:Shardsofmetal/monobook.css" );</code>, then preview the page. When it loads the next page, see if there is an exclaimation icon on the left side of the status bar. If so, double-click it. I had 2 errors, but I know the one related to this is the one I posted. My guess is also that the line number might differ depending on what other javascript has been loaded. I normally use Firefox, I actually only used IE to test this function at my local wiki, to load a custom skin for IE users (since the normal custom skin doesn't look good in IE). However, if I can't get the css file to load, then it was a waste of my time. I don't know javascript, only the basics I've figured out from looking at code, so I can't figure out what the problem is, but I assume that someone who knows javascript can fix the problem. Also, shouldn't the line <code>+ '&action=raw&ctype=text/css";'</code> contain a semicolon at the end, to end the declaration of the variable? Anyway, I hope someone can take a look at this. '''<span style="background: #fadb23; border:1px solid #FF6600; margin-right: .25em; margin-left: .25em">&nbsp;[[User:Shardsofmetal|<font color="blue">Shards</font>]][[Special:Contributions/Shardsofmetal|<font color="#177245">of</font>]][[User talk:Shardsofmetal|<font color="black">metal</font>]]&nbsp;</span>''' 03:04, 3 October 2007 (UTC)
 
:You need to specify a fully qualified URL, not a wikilink as you are trying to do. Try this instead:
importStylesheet("http://en.wikipedia.org/w/index.php?title=User:Shardsofmetal/monobook.css&action=raw&ctype=text/css");
: <span style="font-family: verdana;"> — [[User:Edokter|<span style="color: #008;">'''''E''dokter'''</span>]] • [[User_talk:Edokter|<span style="color: #080;">Talk</span>]] • </span> 11:54, 3 October 2007 (UTC)
 
::No you don't. The function begins:
<source lang="javascript"> function importStylesheet( page ) {
var sheet = '@import "'
+ wgScriptPath
+ '/index.php?title='
+ encodeURIComponent( page.replace( / /g, '_' ) )
+ '&action=raw&ctype=text/css";'</source>
::Therefore, it requests the url /w/index.php?title=THE_PAGE_YOU_REQUESTED&action=raw&ctype=text/css. The function works fine in Firefox, and it looks fine to me, so I don't know why it doesn't work in IE. '''<span style="background: #fadb23; border:1px solid #FF6600; margin-right: .25em; margin-left: .25em">&nbsp;[[User:Shardsofmetal|<font color="blue">Shards</font>]][[Special:Contributions/Shardsofmetal|<font color="#177245">of</font>]][[User talk:Shardsofmetal|<font color="black">metal</font>]]&nbsp;</span>''' 12:55, 3 October 2007 (UTC)
 
:::Right, I missed that. Anyway, I tried the test above, and I didn't get the error. <span style="font-family: verdana;"> — [[User:Edokter|<span style="color: #008;">'''''E''dokter'''</span>]] • [[User_talk:Edokter|<span style="color: #080;">Talk</span>]] • </span> 13:31, 3 October 2007 (UTC)
 
Yes, it's a known problem, importStylesheet doesn't work in IE. When I looked into it some time ago, looks like in IE you're not supposed to add a text node as a child of a <code>style</code> element but instead use <code>styleElem.styleSheet.cssText</code>. But even after that it seems IE (at least IE6) simply doesn't like <tt>@import</tt> in the added text. On the other hand, something like this below seems to work in IE6/Firefox 1.5/Opera 9 ∴ [[User:Alex Smotrov|Alex Smotrov]] 19:20, 3 October 2007 (UTC)
<source lang=javascript>
function importStylesheet(page) {
var styleEl = document.createElement('link')
styleEl.type = 'text/css'
styleEl.rel = 'stylesheet'
styleEl.href = wgScript + '?title='
+ encodeURIComponent(page.replace(/ /g, '_')) + '&action=raw&ctype=text/css'
document.getElementsByTagName('head')[0].appendChild(styleEl)
}
</source>