Closed Thread Icon

Topic awaiting preservation: Slight problem with JS visibility script (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26127" title="Pages that link to Topic awaiting preservation: Slight problem with JS visibility script (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Slight problem with JS visibility script <span class="small">(Page 1 of 1)</span>\

 
Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 06-30-2005 11:21

To the JS Wizards of the Asylum: Greetings and Salutations!

I have a little problem with a script I'm using, but my knowledge of JS has deteriorated to a level somewhere just above "imbecilic." That is, I can look at a script and say, "Hmm... OK, I think I know what's going on here." But forget about correcting problems, let alone even finding them in the first place. That is where you fine folks come in.

First, a link:

http://www.liminality.org/misc/hanmun/

Next, a word of warning: The (albeit miniscule amount of) text on this page is in Korean, so if your system doesn't support Korean text, you will most likely only see gibberish. This shouldn't matter, though, because the issue is very straightforward.

Anyway, on the first page you will see two plain text links at the top. Click on either one of them (it doesn't matter which, as the behavior is ultimately the same). If all goes well, you will see a series of blue boxes running down the page with Korean/Chinese/gibberish in them. If you click on the Korean/Chinese/gibberish text, a pink box should appear to the right (containing Chinese/Korean/gibberish, depending on what's in the left-hand box). If you click on the text in the pink box, it should disappear again.

Now, the problem occurs when you click on a box that is "below the fold" (i.e., below the first screen). Anytime you click on a box (be it blue or pink) below the fold, the page will jump back to the top. I didn't notice this when I was testing the page because I only had a few items and didn't have to scroll down. Now I think I have 60 or items, and it gets pretty annoying to have to scroll down again every time I click on a box.

The script called (known as "dom2.js") is as follows:

code:
var d = 0;
var id = 0;
var all = 0;
var layer = 0;


if (document.getElementById) {id = 1; d = 1;}
else {
if (document.all) {all = 1; d = 1;}
else {
browserVersion = parseInt(navigator.appVersion);
if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {layer = 1; d = 1;}
}}

function dom(objectID,withStyle) {
     if (withStyle == 1) {
          if (id) { return (document.getElementById(objectID).style) ; }
          else { 
               if (all) { return (document.all[objectID].style); }
          else {
               if (layer) { return (document.layers[objectID]); }
          };}
     }
     else {
          if (id) { return (document.getElementById(objectID)) ; }
          else { 
               if (all) { return (document.all[objectID]); }
          else {
               if (layer) { return (document.layers[objectID]); }
          };}
     }
}



The website I got this code from appears to be defunct, so I haven't been able to go back and do any more research. My questions are simple:

  1. Is there anything in this script that makes it jump back to the top of the page every time it is called, or
  2. Is this normal behavior, and most importantly
  3. Is there anything I can do to get around this (that is, have the page stay where it is when the script is called)?



Alternatively, if anyone knows of a visibility script that does not suffer from this "feature," I would be glad to hear about it. It may be a very simple thing, but the chances of me being able to write my own script are slim to none. No, wait. Slim just got cut in half by a chainsaw-wielding psychopath. So that leaves none.

Also, I find this interesting, and I wonder if it is not related to the issue at hand: every time you click on one of those "Insert UBB Code" buttons to the left, the message window jumps back up to the top. Hmm....

Anyway, any help will be appreciated. The current behavior makes using the page so frustrating as to be more or less useless.

Oh, and ignore the rest of the code (HTML, CSS). I haven't tried to validate it yet, and the CSS is still a bit of a haphazard job. Thanks.

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

HZR
Paranoid (IV) Inmate

From: Cold Sweden
Insane since: Jul 2002

posted posted 06-30-2005 11:59

href="#" means "go to the top of the document". The simplest solution (but not the best since that wouldn't involve anchors at all) is to just append "return false" to each "onclick value", i.e.,

code:
onclick="setVisibility('answer0','visible'); return false"



(Edited by HZR on 06-30-2005 12:12)

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 06-30-2005 13:39

Dear God do I feel stupid.

I really should have known that. Thanks.

I put the function call directly in the href and removed the onclick, like so:

code:
<a href="javascript:setVisibility('answer2','visible');">



Do you think this is a better way to do it?

Anyway, it works, and it's now uploaded (original link in the first post points here) just in case anyone wants to practice their Chinese characters... in Korean.

Thanks again!

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

« BackwardsOnwards »

Show Forum Drop Down Menu