473,385 Members | 1,588 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.

<noscript> alternative for random image changer

Afaik the use of a <noscriptelement is frowned upon nowadays. For a JS
random image changer I tried to use a replacement by having the script
change the HTML src attribute value of an img element. The trouble is
that in some situations like over slow connections (on initial load when
the JS is in an external file), or with a slow client the image
specified in the HTML starts to load and display before it's changed by
the script. This I'm not happy with.

Simplified demo:
http://homepage.ntlworld.ie/spartani...lternative.htm

Using a solution like using CSS to initially switch the display of the
image off, then enable it again via JS makes the solution dependant on
JS, so that's out (and it can cause an ugly reflow).

Is there a way to prevent this problem?

--
Spartanicus
Jul 26 '06 #1
7 2322
Spartanicus <in*****@invalid.invalidwrote:
Afaik the use of a <noscriptelement is frowned upon nowadays.
<question rhetorical="no">
Why would that be so?
</question>

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Jul 26 '06 #2
Christopher Benson-Manica said the following on 7/26/2006 2:57 PM:
Spartanicus <in*****@invalid.invalidwrote:
>Afaik the use of a <noscriptelement is frowned upon nowadays.

<question rhetorical="no">
Why would that be so?
</question>
Because there are better, more dependable, alternatives to it.

The <noscriptelement lends itself to attempting to explain why you had
to make script dependent pages. Make your pages script independent, then
use script to enhance them. When you start doing that, you will find
yourself asking "Why did I ever use it to begin with?"

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 26 '06 #3
Spartanicus wrote:
<snip>
Using a solution like using CSS to initially switch the display
of the image off, then enable it again via JS makes the solution
dependant on JS, so that's out (and it can cause an ugly reflow).
You can certainly avoid the dependency on javascript by having an inline
script initially hide the contents as the page is loading and then
re-show the contents in the onload event handler. So if the scripting
cannot initially hide the contents they are never hidden, which is the
correct outcome as the inability to hide them should reflect an
inability to reveal them again later.

Re-flowing is a slightly more difficult question, but using
visibility:hidden; in pace of display:none; may stop the user from
seeing the elements until after they re-flow (following whatever DOM
manipulation your script is planning.

Richard.
Jul 26 '06 #4
Christopher Benson-Manica wrote:
Spartanicus <in*****@invalid.invalidwrote:
>Afaik the use of a <noscriptelement is frowned upon
nowadays.

<question rhetorical="no">
Why would that be so?
</question>
When a scripted web page arrives at a browser there are 3 main
possibilities:-

1. The browser is capable of executing scripts, scripting is enabled
and the browser fully supports all the facilities and features
needed by the script in order for it to act as intended.
2. The browser is incapable of executing scripts or scripting in
disabled. The script will not be able to act at all. (the contents
of NOSCRIPT elements will be dispalyed.)
3. The browser supports scripting and it is enabled, but it does not
provide all the features and facilities required by the script (or
its scripting language is not the one used by the script (unlikely
but possible)). The script will not be able to act (either through
choice or because it errors out, the later being avoidable with
appropriate feature detection testing).

The NOSCRIPT element accommodates the second possibility, with the
acting script accommodating the first. This (near) mutually exclusive
relationship between scripting being enabled and the use of the contents
of the NOSCRIPT element does not address the third possibility. However,
scripts/pages/systems designed for clean-degradation to viable
underlying HTML when a browser does not provide the required scriptable
features/facilities does accommodate the third possibility, and because
a script not being able to act because of a browser's lack of support
for needed features is not distinct from a script not being able to act
because scripting is disabled/unavailable the second possibility is also
accommodated. Thus designing for clean degradation accommodates all the
possibilities while the use of the NOSCRIPT element leaves one
undressed.

Any design that disregards such a significant known possibility is
incomplete, and so the use of NOSCRIPT elements is indicative of
incomplete script design.

Richard.
Jul 26 '06 #5
"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote:
>Using a solution like using CSS to initially switch the display
of the image off, then enable it again via JS makes the solution
dependant on JS, so that's out (and it can cause an ugly reflow).

You can certainly avoid the dependency on javascript by having an inline
script initially hide the contents as the page is loading and then
re-show the contents in the onload event handler.
That would solve one of the problems I described (an external JS file
loading after the HTML page). But it doesn't solve the other case (a
slow client). Using Opera or Firefox I see the first image being
displayed before it is replaced by the script in the example I provided
which uses in document script code.

--
Spartanicus
Jul 26 '06 #6
Spartanicus wrote:
"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote:
>>Using a solution like using CSS to initially switch
the display of the image off, then enable it again
via JS makes the solution dependant on JS, so that's
out (and it can cause an ugly reflow).

You can certainly avoid the dependency on javascript by
having an inline script initially hide the contents as
the page is loading and then re-show the contents in the
onload event handler.

That would solve one of the problems I described (an
external JS file loading after the HTML page). But it
doesn't solve the other case (a slow client). Using Opera
or Firefox I see the first image being displayed before it
is replaced by the script in the example I provided which
uses in document script code.
I think you are being pessimistic. Try this (you will have to provide
your own images):-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<style type="text/css">
IMG {
float:right;
}
</style>
<body>
<script type="text/javascript">
/* The body should be defined at this point so make
it invisible if it can be found:-
*/
if(
(document.body)&&
(document.body.style)
){
document.body.style.visibility = 'hidden';
window.onload = function(){
var img, c, div;
/* "Gateway" test for the required features:-
*/
if(
(document.images)&&
(c = document.images.length)&&
(img = document.images[--c])&&
(img.appendChild)&&
(img.removeChild)&&
(document.createElement)
){
/* Re-arrange the DOM and deprive the images of their
float styles, so that any rendering prior to the
re-arrangement is apparent. This takes the place of
your script initialisation code:-
*/
do{
img.style.cssFloat = img.style.styleFloat = 'none';
div = document.createElement('DIV');
document.body.appendChild(div);
div.appendChild(img);
}while(img = document.images[--c]);
}
/* Make the body visible again, regardless of the success of
the DOM re-arrangement as the user will still need to see
the content:-
*/
document.body.style.visibility = '';
}
}
</script>
<img src="images/grid50x50_Cyan.gif">
<img src="images/grid50x50_Cyan_K.gif">
<img src="images/grid50x50_Cyan_P.gif">
<img src="images/grid50x50_Cyan_Y.gif">
<img src="images/grid50x50_Mag.gif">
<img src="images/grid50x50_Mag_K.gif">
<img src="images/grid50x50_Mag_P.gif">
<img src="images/grid50x50_Mag_Y.gif">
<img src="images/grid50x50_Yellow.gif">
<img src="images/grid50x50_Yellow_K.gif">
<img src="images/grid50x50_Yellow_P.gif">
<img src="images/grid50x50_Yellow_Y.gif">
</body>
</html>

Richard.
Jul 26 '06 #7
"Richard Cornford" <Ri*****@litotes.demon.co.ukwrote:
>>You can certainly avoid the dependency on javascript by
having an inline script initially hide the contents as
the page is loading and then re-show the contents in the
onload event handler.

That would solve one of the problems I described (an
external JS file loading after the HTML page). But it
doesn't solve the other case (a slow client). Using Opera
or Firefox I see the first image being displayed before it
is replaced by the script in the example I provided which
uses in document script code.

I think you are being pessimistic. Try this (you will have to provide
your own images):-
[snip code example]

Sorry that code is to far above my skill level.

Before posting I experimented with using CSS display:none or
visibility:hidden and then negating that with the script, it got rid of
the initial image being displayed by Opera, but not Firefox.

Also, using the visibility property prevents a reflow, but it doesn't
prevent the image from being retrieved, in fact neither does
display:none in certain browsers IIRC.

--
Spartanicus
Jul 26 '06 #8

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

Similar topics

6
by: Gustav Medler | last post by:
Hello, there is a known problem with Opera and the execution of content shown in <NOSCRIPT> tag. Everythings works fine, if there is only one simple script like:...
2
by: llaxman | last post by:
Hello everyone, I was wondering if anyone can help me? I am having some problems wit the <noscript> tag. I actually use it to block banner advertisements from being displaye in my website. I...
12
by: Burton Figg | last post by:
My homepage, www.jimpix.co.uk uses transitional XHTML. The whole thing validates except one line: <noscript><img height="1" width="1" alt=""...
13
by: Paul | last post by:
Hello: I read the FAQ about embedding HTML code in a Javascript. I have used the "<\/tag>" format to get around validator problems. Now the <NOSCRIPT> block is failing with error #65: 1. ...
1
by: Gretsch | last post by:
I have a lot of nicely formatted HTML to be displayed for visitors WITHOUT script (/enabled), and a second set of HTML for those WITH script. The <noscript> tag allows me to separate the HTML for...
28
by: FreeCopywritingTips | last post by:
Does anyone know how to get around the </noscriptissue, were my HTML editor refuses to save this tag?
4
by: phpmel | last post by:
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script language="JavaScript"...
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: 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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.