Johan

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJohan
ToMe
Subjectneed a hand to rewrite a Javascript
Date24 May 2005 14:01
Hi,

I am trying to make a script work from PPK(quirksmode.org) - it is an  image
rollover that can hold a clicked state of that imagelink when clicked-

This is the page where a rollover image script works witht W3CDOM properties

http://www.quirksmode.org/js/mouseov.html

There is another script that is an extension (but much older script it works
also in W3CDOM deprived browser versions-builds)?

http://www.quirksmode.org/js/click.html

The whole idea is that I want to make the click version work exactly as the
mouseover version.

This is what I came up with:

> var W3CDOM = (document.createElement && document.getElementsByTagName);
>
> var mouseOvers = new Array();
> var mouseOuts = new Array();
> var mouseClicks = new Array();
> var select = -1;
> var temp = 0;
>
> function init()
> {
>     if (!W3CDOM) return;
>     var nav = document.getElementById('mouseovers');
>     var imgs = nav.getElementsByTagName('img');
>     for (var i=0;i<imgs.length;i++)
>     {
>         imgs[i].onmouseover = mouseGoesOver;
>         imgs[i].onmouseout = mouseGoesOut;
>         imgs[i].onclick = mouseGoesClick;
>         var suffix = imgs[i].src.substring(imgs[i].src.lastIndexOf('.'));
>         mouseOuts[i] = new Image();
>         mouseOuts[i].src = imgs[i].src;
>         mouseOvers[i] = new Image();
>         mouseOvers[i].src = imgs[i].src.substring(0,
>           imgs[i].src.lastIndexOf('.')) + "_omo" + suffix;
>         imgs[i].number = i;
>         mouseClicks[i] = new Image();
>         mouseClicks[i].src = imgs[i].src.substring(0,
>           imgs[i].src.lastIndexOf('.')) + "_clic" + suffix;
>         imgs[i].number = i;
>     }
> }
>
> function mouseGoesOver(no)
> {
>  if (document.images && select ! = no)
>    {
>     this.src = mouseOvers[this.number].src;
>    }
> }
>
> function mouseGoesOut(no)
> {
>  if (document.images && select != no)
>    {
>     this.src = mouseOuts[this.number].src;
>    }
> }
> function mouseGoesClick(no)
> {
>     this.src = mouseClicks[this.number].src;
>     temp = select;
>     select = no;
>     if (temp != -1) {mouseGoesOut(temp)}
> }
>

Regards


Johan.
FromMe
ToJohan
SubjectRe: need a hand to rewrite a Javascript
Date24 May 2005 15:14
Johan,

You are making a few mistakes with your script;
> function mouseGoesOver(no)
When the function is activated, it will be passed an event object. The event
object has absolutely nothing to do with the state of the image.
http://www.howtocreate.co.uk/tutorials/javascript/eventinfo

> var W3CDOM = (document.createElement && document.getElementsByTagName);

There is no need for the 'document.createElement' check, since you are not
using it. All you are using is document.getElementsByTagName, so that is all
you need to check for;
var W3CDOM = document.getElementsByTagName;

There is also no need to keep checking for document.images, since the DOM
will have already referenced them for us.

To get the click effect working, use these three event handler functions:

function mouseGoesOver() {
  if(this.isClicked) { return; }
  this.src = mouseOvers[this.number].src;
}
function mouseGoesOut() {
  if(this.isClicked) { return; }
  this.src = mouseOuts[this.number].src;
}
function mouseGoesClick() {
  //toggle the clicked state
  this.isClicked = !this.isClicked;
  if( this.isClicked ) {
      this.src = mouseClicks[this.number].src;
  }
  this.onmouseover(); //this will sort itself out
}

Now you can throw these away, since you are not using them:
var select = -1;
var temp = 0;

While you are at it, you only need this line once, not twice:
imgs[i].number = i;


Hope this does what you needed

Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromJohan
ToMe
Subjecthow to remove inline style attributes in NN4
Date26 June 2005 12:39
Hi,

I have made a kind of basic stylesheet to support the obscure netscape 4.x
user.
All fine. Except I used inline styles [needed for advanced layout capable of
CSS2 and up] and want netscape 4.x  to ignore them.
I want to remove the inline styles on which NN4.x chokes so all ancient
browsers which cannot handle the advanced layout and javascript do a nice
job in degrading nicely.

See example code
<ul>
    <li style="width: 100px;">
        <a style="width: 100px;" href="someImage.html">
            <img style="width: 100px;" src="someThumb.jpg"
            alt="" width="100" height="100">
        </a>
    </li>   
</ul>


How can I set the inline style to null or better even remove them in eg Netscape 4?

So when doing object detection

if (!document.getElementById)
{
function remove inline styles here for eg Netscape 4.x editions
}

[Ed. This is an invalid construct - do not use it]

Kind regards,

Johan
FromMe
ToJohan
SubjectRe: how to remove inline style attributes in NN4
Date26 June 2005 13:38
Johan,

> How can I set the inline style to null or better even remove them in eg
> Netscape 4?

Simply, you cannot. Netscape 4 was not advanced enough to do anoything like
this. If you want netscape 4 to ignore it, you must use another format to
make it ignore it. I do not know any way to do this with inline styles
(unless you want to make your document invalid).

The easy way is to apply the styles using classes, and either use a multiple
class, a media attribute, or an @import rule, all of which will be ignored
by Netscape 4:

<link rel="stylesheet" type="text/css" href="extrastyles.css" media="all">
<li class="width100">

<style type="text/css">
@import url(extrastyles.css);
</style>
<li class="width100">

<style type="text/css">
li.width100 { width: 100%; }
</style>
<li class="width100 ignoremenn4">

there are a few other tricks you can also use, but these ones I have shown
you are the most useful and reliable.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromJohan
ToMe
SubjectRe: how to remove inline style attributes in NN4
Date26 June 2005 14:45
Thank you for replying so quickly.  I tried the percentage instead of pixel
width. No go.

To set the width from a px width to a percentage width is not an option.
 I use a css-based multi-rollover for a thumbnail section.

If I would go for an em-percentage based layout maybe this could be an
option. Plus the thumbnails  can vary in width too and the overall  height
is fixed though.

media="all"

You can opt for media="screen, projection" too to exclude eg Netscape 4.x -
but media="all"  stands for all media like screen, projection, print

I also figured out for Netscape 4.x in this case tested a mac version this:

- inline styles on A tags  choke in Netscape 4.x - meaning anchors not
 clickable.
- inlines styles on other elements in Netscape 4.x - it does not matter.
FromJohan
ToMe
Subjecthide images from old browsers like IE3 NN4
Date26 June 2005 23:07
Hi Tarquin,

I want to know if NN3 or IE3 are able to hide an image tag much so as the
equivalent CSS property display: none?

These images (arrows up and down and drag button) I need to be hidden are
part of a div scroller that does not work in IE3 or NN3.

So I decided to go for that one user or even two browsing a webpage with IE3
and NN4 and show the paragraph sections [read text contained in p-tags].

sample code

<div id="up">
    <span title="scroll text ">
<img src="up.gif" alt="" height="12" width="21">
    </span>
</div>

How can you with JavaScript hide the image in IE3 or NN3 for that matter?

Cheers,


Johan
FromMe
ToJohan
SubjectRe: how to remove inline style attributes in NN4
Date27 June 2005 10:36
>> li.width100 { width: 100%; }
>
> To set the width from a px width to a percentage width is not an option.

That's ok, px or % makes no difference. It is the way I was applying the
style that makes Netscape 4 ignore it. The actual styles used are not
important.

>> oops, that link tag should have had a media="all" attribute
>
> You can opt for media="screen, projection" too to exclude eg Netscape
> 4.x - but media="all"  stands for all media like screen, projection,
> print

yes, you can, but then browsers for devices and tvs etc. will not be styled.
Unless you have a good reason to give them a non-styled web page, I suggest
using media="all" since it simultaneously styles all media types, but still
excludes Netscape 4.

> - inline styles on A tags  choke in Netscape 4.x - meaning anchors not
> clickable.
> - inlines styles on other elements in Netscape 4.x - it does not
> matter.

I can come up with plenty of other styles that can make Netscape 4 screw up
(border style on images, for example). The fact that these styles are inline
should have little bearing on things. As long as it applies the styles, it
will screw up.

> I want to know if NN3 or IE3 are able to hide an image tag much so as
> the equivalent CSS property display: none?

No. IE 3 could do basic CSS, but I do not know if display:none; was in its
repertoire.

> How can you with JavaScript hide the image in IE3 or NN3 for that
> matter?

You cannot. These browsers only had limited JavaScript support. Netscape 3
could change the SRC of an image. IE 3 could not even do that.

What you can do is something like this (not recommended);
<style type="text/css">
img.myimg { height: 12px !important; width: 21px !important; }
</style>
<img src="up.gif" class="myimg" height="0" width="0" alt="">

I have no idea what side effects that may have in other browsers. To be
honest, you are much better off just ignoring NN3 and IE3. Who cares?! If
someone is still using those, their entire view of the web is screwed up
anyway, a couple of extra images will not hurt.
FromJohan
ToMe
SubjectRe: how to remove inline style attributes in NN4
Date27 June 2005 12:14
> img.myimg { height: 12px !important; width: 21px !important; }
> I have no idea what side effects that may have in other browsers.
> To be honest, you are much better off just ignoring NN3 and IE3.

Thanks again for the quick reply. The !important rule I tested in IE WIN 6
only to overrule a rule - but it is not working good cross-browser.
I think due to the legacy of this rule - I fo
If set the !important rule to target one specific browser eg IE6 WIN than I
could do this.

I found that if redeclaring the same rule within the same declaration IE
ignores the ! important rule

Otherwise the only way  to find out is testing it.

I found another way too.
If would use a transparent gif , 1px by 1px  [needed to comply for W3C
standards plus old browsers will display transparent gif]
set a class inside the img-tag  the drag.gif as background with an extra
rule for img display: block or display: inline so can use positioning rule
Therefore eliminate the use of !important rule.


eg for the drag button

CSS

#drag {
cursor: pointer;
 z-index: 4;
position: relative;
/* this was first position: absolute;  top: 132px;  left: 647px;  but
changed it because otherwise the drag button would be positioned absolutely
towards viewport but position: relative can be buggy and sometimes a
livesaver */

img.drag-rpl {
background: url(/images/drag.gif) no-repeat top left;
height: 12px;
width: 21px;
position: absolute;
top: 132px;
 left: 647px;
display: inline /* maybe display: block is better idea - dont know really */
}

<code>

<div id="drag">
<img class="drag-rpl" src="transparent.gif" height="" width="" alt="">
</div>
<!-- // drag button -->

</code>

regards,


Johan.
FromJohan
ToMe
SubjectRe: how to remove inline style attributes in NN4
Date27 June 2005 14:13
Tarquin,

It is always nice to experiment with trial and error. But I am going to
leave the images as they are. I am glad my div scroller even work in NN4.

I think if you want to degrade everything  for old browser sake - the way
the source is built that it is also reflected without styling.


Cheers.
FromJohan
ToMe
SubjectSafari bug - append script through DOM
Date27 July 2005 12:03
Dear Tarquin

I would like if possible you could give me some feedbak about this script:
Safari does not seem to append an external js to throught DOM. Would a
document.write to append the script be the alternative then for Safari?
I checked the DOM inspector - it is not

<code>
var W3CDOM = document.createElement && document.getElementsByTagName;
function includeJs(jsPath){
 // check browser support W3CDOM
if (!W3CDOM) {return;}
  var js = document.createElement("script");
  js.setAttribute("type", "text/javascript");
  js.setAttribute("src", jsPath);
  document.getElementsByTagName("head")[0].appendChild(js);
}
    /* some helper function to enable load of multiple functions without
    them being overwritten*/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(includeJs("/js/scriptOnejs"));
addLoadEvent(includeJs("/js/scriptTwo.js"));

</code>


Regards,


Johan
FromJohan
ToMe
SubjectRe: Safari bug - append script through DOM
Date27 July 2005 13:13
Johan,

> Safari does not seem to append an external js to throught DOM.

Correct, it does not - an issue I covered on
http://www.howtocreate.co.uk/loadingExternalData.html

> Would a document.write to append the script be the alternative then for
Safari?

not necessarily. using document.write after the page has loaded will
replace the page with a new page containing only the new content. However,
you could run a script immediately before the end of the body that adds any
scripts you need - that should have the desired effect in all browsers, as
long as you only need to add them at "onload" time:

<script type="text/javascript">
var newScripts = [];
newScripts[newScripts.length] = '/js/scriptOnejs';
newScripts[newScripts.length] = '/js/scriptTwojs';
</script>

...rest of page...

<script type="text/javascript">
for( var i = 0, j; j = newScripts[i]; i++ ) {
    document.write('<script src=\"'+j+'\"'+
      'type=\"text\/javascript\"><\/script>');
}
</script>
</body>


If you need to do this after the page has loaded, sorry, but you are out of
luck.
FromJohan
ToMe
SubjectRe: Safari bug - append script through DOM
Date28 July 2005 13:04
Dear Tarquin,

I understand it would be best to load any external scripts first without any
window.onload or similar event handler
to ensure the external javascripts have loaded.

The whole idea was to exclude non DOM browsers and IE Mac because the other
scripts that follow  do work
ok in the latter browser. What I wanted to do was to browser sniff for Ie5
mac and exclude the external scripts scriptOne and scriptTwo
because they are full of advanced Dom scripts and Ie5 mac choked on them,
even the perfectly working init.js (some DOM nav script) in Ie5 mac
did not do anything  as long the other externals were explicit hard-coded
like this. the funny thing was that even the scripts are excluded from Ie5
Mac the
scripts seemed to be loaded somehow. But my idea did work, and all scritps
could remain external.

this did not work:
<head>
<script type="text/javascript" src="init.js"><script>
<script type="text/javascript" src="scriptOnejs"><script>
<script type="text/javascript" src="scriptTwo.js"><script>
</head>

This did work:

<head>
<script type="text/javascript" src="init.js"><script>
</head>

code: init.js

Like this:

var W3CDOM = document.getElementsByTagName && document.createElement;
var ie5Mac = (navigator.userAgent.indexOf('MSIE 5') != -1  && 
 navigator.userAgent.indexOf('Mac') != -1);
var browserSafari = /safari/i.test(navigator.userAgent);
  
function includeJs(jsPath) {
    // check browser support W3CDOM
    // to support ie5 mac and avoid any runtime errors in the latter browser
    // explicit excluded ie5 mac here,     if (!W3CDOM || ie5Mac) { return; }
      var js = document.createElement("script");
    js.setAttribute("type", "text/javascript");
    js.setAttribute("src", jsPath);
     document.getElementsByTagName("head")[0].appendChild(js);
}
includeJs("/js/scriptOne.js");
includeJs("/js/scriptTwo.js");

// if previous method fails, fix Safari, ie5 mac allready excluded
// ie5 mac does not do anything with theexternal scripts just fixed
// some syntax here and there
// so ie5 mac does not throw any runtime errors
// Maybe TODO: browsers that support W3CDOM could be added here though
// eg Opera 7 and up support the CSS and Js
if (browserSafari) {
    document.write('<script type="text/javascript" src="/js/scriptOne.js"><\/script>');
    document.write('\n');
    document.write('<script type="text/javascript" src="/js/scriptTwo.js"><\/script>');
}

// other scripts
addLoadEvent(init.js)

 are these script equal then:

 <script type="text/javascript">
 var newScripts = [];
 newScripts[newScripts.length] = '/js/scriptOnejs';
 newScripts[newScripts.length] = '/js/scriptTwojs';
 </script>

 ...rest of page...

 <script type="text/javascript">
 for( var i = 0, j; j = newScripts[i]; i++ ) {
 document.write('<script src=\"'+j+'\"'+
 'type=\"text\/javascript\"><\/script>');
 }
 </script>
 </body>

and (difference here, this code is in init.js in the head)

document.write('<script type="text/javascript" src="/js/scriptOne.js"><\/script>');
document.write('\n');
document.write('<script type="text/javascript" src="/js/scriptTwo.js"><\/script>');
yours seems better ...

> If you need to do this after the page has loaded, sorry, but you are out
> of luck.

Again in the head without the external scripts being added without waiting
the page has loaded seems the way to go to ensure they are loaded
Hope you understood what i wanted to bring accross ... Thanks again for all
assistance, in advance.

Regards,
Johan
FromMe
ToJohan
SubjectRe: Safari bug - append script through DOM
Date29 July 2005 14:36
Johan,

> The whole idea was to exclude non DOM browsers and IE Mac because the
> other scripts that follow  do work ok in the latter browser.

Then do your sniff/compat-check and put it around my for loop, so the for
loop is only run if your 'if' statement is satisfied. That way you do not
bump into the safari problem.

Tarquin
FromJohan
ToMe
Subjectappend js right after the title tag
Date17 August 2005 14:48
Hi Tarquin,

The best to you.
You might guess allready from the e-mail title, I am again asking you for
some help (if possible) with a script related to DOM and Js.

My problem
How can I assure that the 'to-be-appended' Js will be right after the title
tag? Is there any way to detect the title tag (Node??) in IE 5 and up, and
then append the Js.

<code>
function ()
{
     var js = document.createElement("script");
   js.setAttribute("language", "JavaScript");
   js.setAttribute("type", "text/javascript");
   js.setAttribute("src", "js/keepieapart.js");
   //    TODO: append this  JS right after title tag regardless of any
   //scripts or stylesheets that are in that page ...
   document.getElementsByTagName('head').item(0).appendChild(js);
     }
</code>

regards,

Johan
FromMe
ToJohan
SubjectRe: append js right after the title tag
Date17 August 2005 16:05
Johan,

In theory you can use insertBefore to insert it before the next sibling of
the title element. If there is no sibling, insertBefore should behave like
appendChild (in other words, it will do exactly what you want).

In practice, IE on Mac will fail if there is no sibling, so a simple check
can be used to ensure it works even if it is the lastChild. Also need to be
careful to ensure that there is a title element:

var oTitle = document.getElementsByTagName('title')[0];
var oHead = document.getElementsByTagName('head')[0];
if( !oTitle ) { oTitle = oHead.lastChild; }
if( oTitle == oHead.lastChild ) {
oHead.appendChild(js);
} else {
oHead.insertBefore(js,oTitle.nextSibling);
}


Tarquin
FromJohan
ToMe
Subjectloading the script: append js right after the title tag
Date17 August 2005 18:39
Hi Tarquin,

-- What I found about loading the script:

I. This first adapted script loaded the script fine:

<code>

function appendJs(jsPath) {

   var js = document.createElement("script");
     var oTitle = document.getElementsByTagName('title')[0];
       var oHead = document.getElementsByTagName('head')[0];
     js.setAttribute("language", "JavaScript");
   js.setAttribute("type", "text/javascript");
   js.setAttribute("src", jsPath);
     if( !oTitle ) {
               oTitle = oHead.lastChild;
                }
                       if( oTitle == oHead.lastChild ) {
           oHead.appendChild(js);
       } else {
           oHead.insertBefore(js,oTitle.nextSibling);
       }
}
appendJs("keepieapart.js");

</code>

II.  This one too:

<code>

function appendJs () {

   var js = document.createElement("script");
   var oTitle = document.getElementsByTagName('title')[0];
   var oHead = document.getElementsByTagName('head')[0];
     js.setAttribute("language", "JavaScript");
   js.setAttribute("type", "text/javascript");
   js.setAttribute("src", "keepiepart.js");
     if( !oTitle ) {
               oTitle = oHead.lastChild;
                }
                       if( oTitle == oHead.lastChild ) {
           oHead.appendChild(js);
       } else {
           oHead.insertBefore(js,oTitle.nextSibling);
       }
}
window.onload = appendJs;

</code>

III. and this function (anonymous) did nothing:
[Ed. Of course not. you have to call the function if you want it to run]

<code>
function  () {

   var js = document.createElement("script");
   var oTitle = document.getElementsByTagName('title')[0];
   var oHead = document.getElementsByTagName('head')[0];
     js.setAttribute("language", "JavaScript");
   js.setAttribute("type", "text/javascript");
   js.setAttribute("src", "keepiepart.js");
     if( !oTitle ) {
               oTitle = oHead.lastChild;
                }
                       if( oTitle == oHead.lastChild ) {
           oHead.appendChild(js);
       } else {
           oHead.insertBefore(js,oTitle.nextSibling);
       }
}
</code>

regards,


Johan
FromJohan
ToMe
SubjectRe: append js right after the title tag
Date23 August 2005 11:14
Hi Tarquin,

Could you help me (if possible)  with this Js 'image preload' script ?
Will it do the job? Are there any remarks on this script?

<code>
   // create array of the images
   var photoArray = new Array(

                               {src:"images/01.jpg"},
                               {src:"images/02.jpg"},
                               {src:"images/03.jpg"},
                              {src:"images/04.jpg"},
                               {src:"images/05.jpg"},
                               {src:"images/06.jpg"},
                               {src:"images/07.jpg"},
                               {src:"images/08.jpg"}
);

   var myImages = new Array();       // loop the array,of the images
   for (var i = 0; i < photoArray.length; i+=1) {
   //  width, height of thumbnails are all 100px by 100px
   myImages[i] = new Image(100, 100);
   //  the actual preloading ('caching') of the array of images
   myImages[i].src = photoArray[i].src;
   }

</code>

Thanks for any help in advance.

Regards,


Johan
FromMe
ToJohan
SubjectRe: will this preload images script work ok ??
Date23 August 2005 12:49
Johan,

yes, it should work, but it could be simpler. Firstly, there is no need to
use objects, since you are only storing one property. Secondly, the optional
height and width do not really serve any purpose (they were only used to
make life easier for Netscape 4)

var photoArray = new Array(
  "images/01.jpg",
  "images/02.jpg",
  "images/03.jpg",
  "images/04.jpg",
  "images/05.jpg",
  "images/06.jpg",
  "images/07.jpg",
  "images/08.jpg"
);
var myImages = new Array();
for (var i = 0; i < photoArray.length; i+=1) {
  myImages[i] = new Image();
  myImages[i].src = photoArray[i];
}


Tarquin
FromJohan
ToMe
SubjectRe: will this preload images script work ok ??
Date23 August 2005 13:24
Tarquin,

Thanks for clarifying this, so no need to add src: to the Array. So the
width and height can be left out ...

Cheers
FromJohan
ToMe
Subjectimage onload not working ok in IE or Opera
Date7 September 2005 12:41
Hi Tarquin,

Could you offer me any help please, if possible, with this javascript
problem?

I have a JS and DOM slideshow that works fine in all modern browsers except
IE and Opera.

Firstly, IE 5.x and IE 6 have problems with loading the appropriate image,
caption and image number with cache settings 'Every Time ..' and
'Automatically'.

In the script I have this:

// Event listeners for onload and onclick events
document.getElementById('Photo').onload = initFade;

The image should be loaded here:

<div id="Container">
<div id="PhotoContainer">
<img id="Photo" src="/images/c.gif" alt="" width="400" height="300">
</div>
</div>

In my page set-up I can navigate from thumbnails to go to the slideshow page
to show 'the asked for' enlarged image, also one can go back and forth to
see the thumbnails again by means of the up arrow button or the back button
of the browser. Here is what happens, when going back to the slideshow page,
these cache settings in IE 'automatically' and 'Every time' fail to load the
images and activate anything else of that slideshow. Other browsers have no
problem what so ever going back and forth these pages.

What struck me is that on this page: <[URL]>, a similar script <[URL]> is
used for a fade in-out slideshow and there all works fine. (tested with the
back-button). So I thought maybe there could be a solution (to add to my
script).

How can this be solved for IE?

Kind Regards,


Johan
FromMe
ToJohan
SubjectRe: image onload not working ok in IE or Opera
Date7 September 2005 16:35
Johan,

> document.getElementById('Photo').onload = initFade;

Ok, I think I know what your problem is. Once the picture has already loaded
(including caching), onload will not fire - makes sense when you think about
it that way. What you need to do is check if it has already loaded
(oImage.complete), and if it has, then run the onload method yourself:

    document.getElementById('Photo').onload = initFade;
    if(document.getElementById('Photo').complete) {
        document.getElementById('Photo').onload();
    }

> Here is what happens, when going back to the slideshow page

I notice that in Opera you cannot use the back button to cycle through the
images. Not really surprising. Opera does not re-initialise the page when
going back, it retains it exactly as it was (which may seem a bit odd when
using fragment links, but it makes a lot of sense). Mozilla is currently
working on the same thing for Firefox.

Opera users are used to this behaviour, and they like it that way, so don't
worry about it.

Tarquin
FromJohan
ToMe
SubjectRe: image onload not working ok in IE or Opera
Date7 September 2005 17:34
Dear Tarquin,

Thank you for the interesting idea. It does force the image to load when the
'image loading' problem occurs.
Only what happens too, it seems that the image is reloading all the time,
the navigation does work, bu then again the image keeps on being reloaded.

Is there a way to keep the loading initiated by
document.getElementById('Photo').onload(); to restrict to only once ?


Johan.
FromJohan
ToMe
SubjectRe: image onload not working ok in IE or Opera
Date7 September 2005 18:41
Dear Tarquin,

This is what I wanted to do but did not know how. Thanks a million.

The images are loaded properly with cache settings 'automatically' and
'everytime you visit'' in IE also the back button works too.

Kind regards,

Johan
FromJohan
ToMe
Subjecthistory.back()
Date23 September 2005 04:56
Hi Tarquin,

I do appologise to ask again for help.

I already have a alert working onclick on the link but the actual function I
want to apply is history.back() like this

I have first this (due to the nature of the function).

loadAPI = function(){
  // Instantiate HTMLobj
  // [CODE SNIP]...

  API.Back  = new HTMLobj('Back');
   }
onload = loadAPI;

// [CODE SNIP]...

// goBack function

function goBack() {
  // test-alert works
  alert('check if onclick works');
  // not working
  history.back();
  }

document.getElementById('Back').onclick = goBack;


I have trouble understanding (because before I did <a
href="javascript:history.back();">)
What comes now inside the href <a href="???" id="Back" ...>

the HTML

<div id="prevnext">
<ul id="prevnext-nav">
<li id="prev"><a id="PrevTextLink" href="#" title="&larr;&nbsp;vorige
beeld">vorige beeld</a></li>
<li id="overview"><a href="???" id="Back" title="overzicht van beelden
project">overzicht</a></li>
<li id="next"><a href="#" id="NextTextLink" title="volgende
beeld&nbsp;&rarr;">volgende beeld</a></li>
</ul>
</div>


Regards,


Johan
FromMe
ToJohan
SubjectRe: history.back()
Date25 September 2005 09:57
Johan,

> loadAPI = function(){
>   // Instantiate HTMLobj
>   // [CODE SNIP]...
>
>   API.Back  = new HTMLobj('Back');
>    }
> onload = loadAPI;

I have no idea what this is. It looks completely redundant to me. I guess
this is Bruno's API? You will have to ask them for more information. Meh,
whatever, from what I can see it is not needed.

Note that I do not support other perople's scripts - I have enough of my own
to support.

> function goBack() {
> ...
> document.getElementById('Back').onclick = goBack;

Are you sure that 'Back' has been created already? You must not run this
script until _after_ Back has been created or it will look for it, and not
be able to find it, so it will throw an error.

anyway, this is all beside the point;

> function goBack() {
>   // test-alert works
>   alert('check if onclick works');
>   // not working
>   history.back();
>   }

If the alert works but the history.back() does not, then something has gone
wrong. It should work (as long as there is actually something in real
history to go back to). If it is not working then maybe the HTMLobj is
conflicting? I don't know, you will need to contact the author of that
script.

Note also that you must return false; at the end of your goBack function, or
browsers are supposed to follow the link to '#' and scroll to the top of the
page.
FromJohan
ToMe
SubjectRe: history.back()
Date26 September 2005 11:40
Tarquin,

History.back() was a wrong choice   (it even did not serve any purpose, a <a
href="" ..> does the trick in this case.
The API is one of those JS libs that is a free licence, (GPL or something)
with copyright notices, you can adapt it as you will.

[snip.]

Thanks again for your assistance,

Kind regards,

Johan
FromJohan
ToMe
Subjectaccomodate height div scroller when resizing font
Date27 September 2005 16:04
Dear Tarquin,

I am asking you (if possible) could help me out with a 'JS scroller' issue.

I have been trying relative font-sizing, so that font-size can be increased
or dicreased.

In IE6 WIN, Moz FF I noticed a similar thing: when resizing the font of my
DIV scroller, the
height of the DIV is not recalculated. Two things happen, decreasing leaves
a surplus of DIV height
which is 'not 'the end of the world' since the text in the scrool box is
still fully accesible, only a
gap stays after the last <p>. When the font-size is enlarged the full text
is cut off. When reloading the page
the div height is recalculated and all is in order.

Do you know if it is possible to do a 'on the fly' recalculation of a div
height for that matter?



a testpage:
<[URL]>

Kind regards,


Johan
FromMe
ToJohan
SubjectRe: accomodate height div scroller when resizing font
Date27 September 2005 16:35
Johan,

> In IE6 WIN, Moz FF I noticed a similar thing: when resizing the font of my
> DIV scroller, the height of the DIV is not recalculated.

Two things:

1. What does Opera do?

2. can you make a small example of it? just a demo of the basic problem.
trying to debug your page is a nightmare.
FromJohan
ToMe
Subjectwindow.onload
Date19 November 2005 17:53
Hi Tarquin,


I have a question about loading JS in the body, just before the end tag.

Eg

<script type="text/javascript">
        Element.cleanWhitespace('content');
        init();
    </script>
</body>


Is there an alternative to do this sort of loading cross-browser in the head ?
Or is the above code an equivalent for <body onload="...>
This way of loading helps to load 'in this case' a DOM script.


Thank you for any help with this forementioned issue.


Kind regards,


Johan
FromMe
ToJohan
SubjectRe: window.onload
Date20 November 2005 00:02
Johan,

> Is there an alternative to do this sort of loading cross-browser in the
> head ?
> Or is the above code an equivalent for <body onload="...>
> This way of loading helps to load 'in this case' a DOM script.

Running a script immediately before </body> is not exactly the same as
onload. It usually runs noticeably before onload.

If a script runs before </body> it does not wait for onload, it runs
immediately, as soon as the DOM is (supposedly) ready. Onload will wait
until at least the dimension information of all embedded images or objects
has been retrieved. Depending on the browser, it may wait for all the
images, objects, and iframes to load completely.

Running a script before the </body> avoids this delay. Note that the DOM
specification does not account for this "not quite complete" state, but in
practice, it will work in all browsers. There is no equivalent (cross
browser) event that can be used for this.

Tarquin
FromJohan
ToMe
Subjectremove textnode after it is created from the array
Date16 March 2006 22:22
Hi Tarquin,

I am asking if you could possibly  help me out with this DOM/JS issue.

I have created an array that holds three textmessages, how can I
remove the created textNode and feed the next message in line? Is
there also an issue with cleaning any whitespace too?

A code snippet:
----------------------

var altTextBanners = new Array(
"myText1",
"myText2",
"myText3");

altTextBanners.currentIndex = -1;

function initRotate() {

if (!document.getElementById) return;

altTextBanners.currentIndex++;

var text = document.createTextNode(altTextBanners[altTextBanners.currentIndex]);
var message = document.getElementById("message");
message.appendChild(text);
// how to remove the created TextNode and get the next one in the array
// ... ??
}

HTML

<span id="message"></span>



Thanks for any help in advance,

Kind regards,


Johan
FromMe
ToJohan
SubjectRe: remove textnode after it is created from the array
Date17 March 2006 17:46
Johan,

I would suggest that you put the increment after you use the counter. That
way, it becomes a simple case of incrementing, then modulo dividing (to get
the remainder) to make sure it goes back to the first one after it does the
last one.

To replace the existing one (if there is one), use replaceChild. Just check
for the firstChild to see if you should replace or create:

var altTextBanners = new Array(
"myText1",
"myText2",
"myText3");

altTextBanners.currentIndex = 0;

function initRotate() {

if (!document.getElementById) return;

var text = document.createTextNode(altTextBanners[altTextBanners.currentIndex]);
var message = document.getElementById("message");
if( message.firstChild ) {
  message.replaceChild(text,message.firstChild);
} else {
  message.appendChild(text);
}

altTextBanners.currentIndex++;
altTextBanners.currentIndex = altTextBanners.currentIndex %
 altTextBanners.length;

}
window.onload = function () {
  initRotate();
  setInterval(initRotate,1000);
};
FromJohan
ToMe
SubjectRe: remove textnode after it is created from the array
Date17 March 2006 18:31
Thank you for helping out, dear Tarquin. I added some functionality
and ran into another issue.

I need a different delay setting when the array is to the end and to
the beginning again:

Something like this:
----------------------------

var delay = 1000;
// 0 or 1?
altTextBanners.currentIndex = -1:

// Set delay to 5 sec when going thru the array again ?

if (altTextBanners.currentIndex >= altTextBanners.length) {
altTextBanners.currentIndex = 0; delay = 5000; }

setInterval froze Safari, Firefox, setTimeout does not?

 window.onload = function () {
    initRotate();
    setInterval(initRotate, delay);
 };




How to the same thing with this method you suggested?

altTextBanners.currentIndex++;
altTextBanners.currentIndex = altTextBanners.currentIndex %
altTextBanners.length;
FromMe
ToJohan
SubjectRe: remove textnode after it is created from the array
Date17 March 2006 18:55
Johan,

> I need a different delay setting when the array is to the end and to
> the beginning again:

ok, I have done this sort of thing in the past, where you could specify the
delay for each message. That is usually the easiest way to do it.

> setInterval froze Safari, Firefox, setTimeout does not?

eek, not surprised though :)
setInterval _keeps_ firing. to do what you were doing, you will have
created a new interval each time you looped, meaning you could get an
infinite number of them - not good.

This should do what you need:

var altTextBanners = new Array(
["myText1",1000],
["myText2",1000],
["myText3",5000]
);

altTextBanners.currentIndex = 0;

function initRotate() {

if (!document.getElementById) return;

var text=document.createTextNode(altTextBanners[altTextBanners.currentIndex][0]);
var message = document.getElementById("message");
if( message.firstChild ) {
  message.replaceChild(text,message.firstChild);
} else {
  message.appendChild(text);
}

setTimeout(initRotate,altTextBanners[altTextBanners.currentIndex][1])

altTextBanners.currentIndex++;
altTextBanners.currentIndex = altTextBanners.currentIndex % altTextBanners.length;

}
window.onload = function () {
  initRotate();
};
FromJohan
ToMe
SubjectRe: remove textnode after it is created from the array
Date17 March 2006 19:47
Tarquin,



Suppose I want to alter the content of the alt attribute of the img
tag using that same Array? Like this

var altTextBanners = new Array(
["myText1",1000],
["myText2",1000],
["myText3",5000]
);

 function initRotate() {
// ... [code snippet]

altTextBanners.currentIndex++;
altTextBanners.currentIndex = altTextBanners.currentIndex %
altTextBanners.length;

element.setAttribute("alt", altTextBanners[altTextBanners.currentIndex][0]);

}


Johan
FromMe
ToJohan
SubjectRe: remove textnode after it is created from the array
Date17 March 2006 19:55
Johan,

> Suppose I want to alter the content of the alt attribute of the img
> tag using that same Array? Like this

Sure, that should work.

> altTextBanners.currentIndex++;
> altTextBanners.currentIndex = altTextBanners.currentIndex %
> altTextBanners.length;

You have these the wrong way round - increment _after_ you use it (and make
sure it is initially set to 0, not -1).
FromJohan
ToMe
SubjectTo remove the inline JS I would like to add a onclick event handler to the JS and find each time the *first next <ul> by using DOM to execute a function.
Date23 March 2006 12:31
Hi Tarquin,

I am puzzled with this.

To remove the inline JS I would like to add a onclick event handler to
the JS and find each time the *first next <ul> by using DOM to execute
a function.

Is it that I need nextSibling or something similar?


CSS

.hiddenAnswer { display: none; }

the HTML

<a href="javascript:toggleAnswer('foldinglist1');">The Question</a>
<a href="javascript:toggleAnswer('foldinglist1');">Reveal the answer</a>

<ul id="foldinglist1" class="hiddenAnswer">
<li>This is the answer</li>
<li><a href="javascript:toggleAnswer('foldinglist1');">Hide Answer</a></li>
</ul>

<a href="javascript:toggleAnswer('foldinglist2);">The Question</a>
<a href="javascript:toggleAnswer('foldinglist2');">Reveal the answer</a>

<ul id="foldinglist2" class="hiddenAnswer">
<li>This is the answer</li>
<li><a href="javascript:toggleAnswer('foldinglist1');">Hide Answer</a></li>
</ul>
 <!-- and so on -->

JS

function toggleAnswer(ul_id) {
   var u = document.getElementById(ul_id);

   if(u.className == "hiddenAnswer") {
      u.className = null;
   } else {
      u.className = "hiddenAnswer";
   }
}

Thanks in advance for any help.



Johan
FromMe
ToJohan
SubjectRe: To remove the inline JS I would like to add a onclick event handler to the JS and find each time the *first next <ul> by using DOM to execute a function.
Date23 March 2006 18:31
Johan,

> Is it that I need nextSibling or something similar?

I recommend avoiding using that as much as possible. IE will ignore the
whitespace, other browsers will not, meaning that next sibling is
unreliable. Just stick with the IDs and move the script into an onclick
handler instead.

>       u.className = null;

null is not a valid value for className. It is a string, so it will assign a
string value of "null", so the class will now be "null". To have the effect
you want, just use an empty string:
foo.className = '';
FromJohan
ToMe
SubjectDOM: Opera fails with customised insertAfter()
Date7 April 2006 13:23
Hi Tarquin,

I am asking your assistance on inserting anchors in a div one after the other.

I have tried to insert <a><img /></a>s one after the other in a div
named lightbox.

As you can see here at the demo page <http://test.zoic.be/sub-scape/>
where you need to click on the image to see a flyer poping up (this
works in Moz FF, Safari) but fails in Opera enterily:

This code < http://test.zoic.be/sub-scape/inc/lightbox.flyer.js>I used
to insert the <a><img /></a>s on top of a image layer underneath them.

// dodgy helper func insertAfter()

function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}

// end

How can I accomplish the same thing that I create an <a> element and
insert it one after the other without this method?

<div>
<a><img /></a>
<a><img /></a>
<a><img /></a>
<a><img /></a>
<a><img /></a>
</div>

Many thanks in advance,


Johan
FromMe
ToJohan
SubjectRe: DOM: Opera fails with customised insertAfter()
Date8 April 2006 09:34
Johan,

> where you need to click on the image to see a flyer poping up (this
> works in Moz FF, Safari) but fails in Opera enterily:

Your demo works for me in Opera 8.52 and Opera 9. The opacity effects
obviously only work in Opera 9, but the mouseover tooltip, and the
click-to-show flyer work fine in both.

If you are still having problems, can you prepare a minimal demo showing
exactly what fails? Preferably just the vary simplest you can get it down
to. Something like just a div (or whatever) with a single span in it, and
try to insertAfter the span.


Tarquin
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.