Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Alert needed to make code work

    Hi

    I wrote the following code to force a page intended for frames into its frameset:
    <pre>function ForceIntoFrames(MyLevelPrefix) {
    if (top == self) {
    var MyURL;
    MyURL=document.URL;
    top.location.href = MyLevelPrefix + "default.htm";
    /* @@@ For some reason, this doesn't work without the alert??? @@@ */
    alert("Click OK to display the page");
    sjBody.location=MyURL;
    }
    }</pre>


    It works okay, but not if I remove the alert. Instead, it processes "top.location.href", displays the default.htm, then stops.
    Added later: sjBody is the name of the target frame.

    Any ideas? I don't have too much experience with JavaScript, so I may be missing something obvious. Or maybe it's some sort of timing issue?

    Thanks
    Dale

  2. #2
    Platinum Lounger
    Join Date
    Feb 2002
    Location
    A Magic Forest in Deepest, Darkest Kent
    Posts
    5,681
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Alert needed to make code work

    Hi Dale

    I am not a javascripter as such as I only dabble but I have found this link:

    jwweb

    and

    webmasterworld

    They both seem to be talking through the same method, could this help you?
    Jerry

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Wellington, Wellington, New Zealand
    Posts
    378
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Alert needed to make code work

    Thanks, Jerry. Those references were very helpful.

    Actually, I think I may just have changed my mind about frames. I like them because they provide an easy way of keeping the navigation in view, even when the user pages down. The big negative, of course, is that bookmarking effectively doesn't work when you use frames.

    However, I've now discovered that <DIV>s can be positioned dynamically (I must have been sleeping when the news came out). I haven't found any example code, yet, but it must be possible to put the navigation in a <DIV> and dynamically keep the <DIV> visible. I presume you would use the onkeyup event (or similar) to trigger the movement.

    Mmmm, interesting.

    Thanks again
    Dale

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Alert needed to make code work

    The CSS spec provides for a "fixed" position div and a scrolling one right beside it. IE apparently does not support this completely, so there are some "hacks" that might be needed to make it work. I'm experimenting with a set of stylesheets for a wiki; you can download them from the source at PmWiki - Cookbook - FixFlowSkin. (In that example, of course, the navigation is too long, but if you customize it for your own site, it should be fine.)

    Added: By the way, regarding the alert, it could be a timing issue: the target document might not be completely loaded, so the code can't run properly yet. You could try using setTimeout() (apologies for any case errors, I did not look it up) to schedule the code to run a few milliseconds in the future and see whether that helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •