Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Junior Member
    Join Date
    Jun 2003
    Posts
    29
    Member #
    1648
    It seems that anchor scrolling (like <a href="#Chapter3">) does not work around code written with document.write(). Regardless of whether I do something like this:

    <a href="#Pos1">
    //document.write() adds a bunch of stuff here
    <a name="Pos1">

    or just having document.write() write the anchor tags along with everything else, scrolling doesn't work. Here's an example: ArghScrolling.html

    Clicking the number next to "in reply to #" doesn't scroll anywhere.
    ~CGameProgrammer( );

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    the problem is that you're generating all of your content between anchors with javascript calls. That means that the browser has no way of determining how much content there really is, because javascript is dynamic.... it's not rendered by the html parsing engine. Therefore, it says to itself "anchors are meaningless in this context" and ignores them when clicked. Get rid of the JS in your body... that's improper use of the <script> element, anyway.... scripts only belong in the <head> portion of the document, whether browsers render them properly or (in this case) not.

  4. #3
    Junior Member
    Join Date
    Jun 2003
    Posts
    29
    Member #
    1648
    Thanks for the reply, but the JavaScript creates the HTML formatting client-side, which makes large groups of comments load MUCH faster, since otherwise you have the exact same HTML tags repeated for every comment and it's wasteful. If there's no way to have the browser dynamically evaluate element positions, then either there's no way for me to fix this or I'll just have to go back to static HTML... but it really does make quite a difference and the site loads pretty slowly as it is.
    ~CGameProgrammer( );

  5. #4
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    it's not wasteful so much as it's explicit. That's how markup languages were intended to be. The bottom line is that's what's causing your problems.

  6. #5
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    PS... have you considered trying DOM instead of document.write to generate the HTML?

    PPS... try putting your javascript in the <head> element and call it with events, like <body onload="myScript()">

  7. #6
    Junior Member
    Join Date
    Jun 2003
    Posts
    29
    Member #
    1648
    Hey, thanks, transio -- I didn't know of DOM. It sounds like it will work correctly but I'll code it up and see for myself. I'll edit this if it works, or doesn't. EDIT: Well it appears not to work, though I just discovered innerHTML, which does work. Here's my test script. By default it uses innerHTML, but save it and edit the body.onLoad() function to call UseDOM() instead, and it won't work. I suspect the problem may be with the bottom anchor I'm creating... I'm not sure. But because I already wrote the comment function to put everything in one string, it's extremely easy adapting it for that instead. DOM is quite a pain, assembling every element bit by bit... ugh. END EDIT.

    As for your PPS comment, when using document.write(), I discovered putting it in a function and calling that function did not work -- the dynamic code basically replaced everything else in the file. I had to write it as a function that returns a string and then document.write the string outside the function call.
    ~CGameProgrammer( );

  8. #7
    Junior Member
    Join Date
    Jun 2003
    Posts
    29
    Member #
    1648
    By the way, check out this cool page I found. I ran the tests by clicking the Test links, and on IE innerHTML is far faster than anything else (with concatenation, specifically).

    I got scrolling working by using innerHTML. Sweet. Looky here. You click the "17" and scroll to post 17. Actually it scrolls so the top of the post is at the top of the screen... is there a way to adjust it so it's more in the center?

    Well thanks for your help, transio; I thought document.write was the only way to alter it.
    ~CGameProgrammer( );


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:36 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com