Opening Window with Javascript problem...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • -DRB-

    Opening Window with Javascript problem...

    Hi all,

    I'm very much an amateur designing a page (for free!) for a friend, so
    any help offered would be hugely appreciated.

    I'm aiming to open a maximised window (and isn't that fun...) and
    found the following script on a freescripts page to do just that... it
    works perfectly.

    Into head section:

    <script language="javas cript">
    <!-- Hide from older browsers
    function openme(){
    w = screen.width;
    h = screen.height;
    ah = h - 25
    nw=window.open( "your_page.htm" ,"",'toolbar=ye s,location=yes, directories=yes ,menubar
    =yes,scrollbars =yes,status=yes ,resizable=1,wi dth='+w+',heigh t='+ah)
    window.nw.moveT o(0,0)
    }
    -->
    </script>


    And the event to open the window:

    <script language="javas cript">
    <!-- Hide from older browsers
    if (document.all){
    document.write( '<a href="#" onclick="openme ()">click here to open a
    full window</a>')
    }
    else{
    document.write( '<a href="your_page .htm">click here to open a full
    window</a>')
    }
    -->
    </script>


    Now, what I would really like to do is to alter this so that I can
    pass the openme function the webpage that I would like to open in a
    maximised window. Preferably, this should work with both internal and
    external webpages. I've tried to tweak this with my minimal knowledge
    of JavaScript but with no success.

    Thanks in advance,

    Dave.
  • David Dorward

    #2
    Re: Opening Window with Javascript problem...

    -DRB- wrote:
    [color=blue]
    > I'm aiming to open a maximised window[/color]

    Why? If the user wants a maximised window, they can click maximise. For that
    matter, if the user wants a new window at all they can choose to have one.

    Attempting to open maximised windows leads to problems like this:



    --
    David Dorward http://dorward.me.uk/

    Comment

    • -DRB-

      #3
      Re: Opening Window with Javascript problem...

      Thanks chaps.... I've got some serious reading to do, but your time
      and effort is appreciated.

      David: I take your point, but this page is just linking them to a
      calendar that looks awfully messy if the page is not automatically
      maximised... agreed though, they could do it it they wanted to I
      hadn't really thought of further consequences.

      Lasse: you weren't wrong when you said 'Strap yourself in'!!! I'm
      going to try to digest everything that you said and try the code in
      what I am working on. I'll let you know how it goes....

      Thanks again!

      Dave.

      Comment

      • -DRB-

        #4
        Re: Opening Window with Javascript problem...

        Hi again...

        ....Text removed here...
        [color=blue]
        >
        >Horrendous. It assumes that only browsers with the Microsoft
        >proprietary "document.a ll" interface can open a window. What millenium
        >is this code from?
        >
        > <a href="your_page .html" onclick="openme (this.href);ret urn false">
        > Open a full screen(!) window
        > </a>
        >[/color]

        Ok, now do I paste the above code into where I want the link to be...
        do I have to wrap around:

        <script type="text/javscript">
        </script>

        Also, let's say that I want to link to a page called test.html

        Would the code be:

        <a href="test.html " onclick="openme (test.html);ret urn false">
        Open a full screen(!) window
        </a>

        or:

        <a href="test.html " onclick="openme ('test.html');r eturn false">
        Open a full screen(!) window
        </a>

        <more snipping>
        [color=blue]
        >I believe it does. Be aware that you will probably reuse the already
        >existing window each time you click on the link. If you want a new
        >window each time, you should change the second argument of the
        >"open" function to "_blank".[/color]

        Sorry.... can you be more precise please... how would I alter the code
        below:

        open(URL,"","to olbar=yes,locat ion=yes,manubar =yes,scrollbars =yes"+
        ",status=yes,wi dth="+w+",heigh t="+h+",left=0, top=0");


        Thanks again for all your help. I guess we all have to start
        somewhere!

        Dave.

        Comment

        • David Dorward

          #5
          Re: Opening Window with Javascript problem...

          -DRB- wrote:
          [color=blue]
          > David: I take your point, but this page is just linking them to a
          > calendar that looks awfully messy if the page is not automatically
          > maximised...[/color]

          So it will look messy in a 1200x1000 window will it? That isn't maximised on
          my system, but its a lot bigger then a maximised window on most peoples
          systems.

          Maximised is fairly meaningless, "less then the size of the window on my
          system when it is maximised" would be more accurate, but not useful unless
          we know what the size is.

          If the design really needs a very large amount of space, I'd seriously
          consider changing the design.

          --
          David Dorward http://dorward.me.uk/

          Comment

          • -DRB-

            #6
            Re: Opening Window with Javascript problem...

            Thanks again for the swift response. Couple of things aren't quite
            working yet.. if you could just stay with me a little while longer...

            When I click on the link I get an error:
            "Error: object expected"

            Also, I've put the _blank bit in and the new page does not load into a
            new window. It is coming from a frame though: could this be part of
            the problem? I've checked, double checked and triple checked that
            I've typed it in correctly (well, as you wrote it):
            [color=blue]
            > open(URL,"_blan k","toolbar=yes ,location=yes,m anubar=yes,scro llbars=yes"+
            > ",status=yes,wi dth="+w+",heigh t="+h+",left=0, top=0");[/color]

            But to no avail. Thanks yet another time!

            Dave.

            Comment

            • -DRB-

              #7
              Re: Opening Window with Javascript problem...

              BY the way, I'm testing the site at:



              If you have the time to take a look (I'm not requesting huge feedback,
              just trying to nail this little problem), the bit I'm concerned with
              is:

              * choose 'Events' off top menu
              * choose Map of UK off left menu
              * choose Scotland.

              It's the bottom link "Visit the Fettes College..." that I'm trying to
              get working.

              Dave.

              Comment

              • Lasse Reichstein Nielsen

                #8
                Re: Opening Window with Javascript problem...

                -DRB- <bog@bog.com> writes:
                [color=blue]
                > www.btinternet.com/~david.boggitt/
                >
                > * choose 'Events' off top menu[/color]

                The image for the Events button is missing.
                Clicking it gives a 404 error here.
                Sorry :)
                /L
                --
                Lasse Reichstein Nielsen - lrn@hotpop.com
                Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
                'Faith without judgement merely degrades the spirit divine.'

                Comment

                • -DRB-

                  #9
                  Re: Opening Window with Javascript problem...

                  Oh bunch of arse, this just gets better and better :-)

                  What browser are you working with...? *sigh*

                  On 13 Aug 2003 18:46:37 +0200, Lasse Reichstein Nielsen
                  <lrn@hotpop.com > wrote:
                  [color=blue]
                  >-DRB- <bog@bog.com> writes:
                  >[color=green]
                  >> www.btinternet.com/~david.boggitt/
                  >>
                  >> * choose 'Events' off top menu[/color]
                  >
                  >The image for the Events button is missing.
                  >Clicking it gives a 404 error here.
                  >Sorry :)
                  >/L[/color]

                  Comment

                  • Lasse Reichstein Nielsen

                    #10
                    Re: Opening Window with Javascript problem...

                    -DRB- <bog@bog.com> writes:
                    [color=blue]
                    > Oh bunch of arse, this just gets better and better :-)
                    >
                    > What browser are you working with...? *sigh*[/color]

                    Opera 7.2beta 3 (w/ Proximitron as proxy).

                    In Mozilla FB 0.6 I have to scroll the buttons into view in the
                    topmost frame. Otherwise it seems to work.

                    Looking at the code, a few things spring to my eyes:
                    The digital clock script checks for the presence of either
                    document.layers or document.all . That means that it will fail
                    in Mozilla, which has neither.

                    This tag: "<script menumaker>" looks pretty odd. I guess the
                    "menumaker" is just misplaced and the type attribute missing.
                    The content of that script is just a document.write that writes
                    another script tag. That is wasteful.


                    As far as I can see, the image for the menu is
                    <URL:http://www.btinternet. com/~david.boggitt/TopNavBar/sm_topnav_b1.gi f>
                    Opera does not have the "TopNavBar/" part of the URL.
                    That part is found by the part of the script that initializes the "loc"
                    variable:
                    ---
                    if (typeof(loc)==" undefined" || loc==""){
                    var loc=""
                    if (document.body& &document.body. innerHTML){
                    var tt = document.body.i nnerHTML.toLowe rCase();
                    var last = tt.indexOf("sm_ topnav.js\"");
                    if (last>0){
                    var first = tt.lastIndexOf( "\"", last);
                    if (first>0 && first<last)
                    loc = document.body.i nnerHTML.substr (first+1,last-first-1);
                    }
                    }
                    }
                    ---
                    Apart from having the innerHTML computed three times (and this is before
                    the page is completely loaded), it is a pretty fragile way of finding
                    the location of the script.

                    It is supposed to find this part:
                    src="TopNavBar/sm_topnav.js"
                    and let loc="TopNavBar/". It fails silently in Opera.
                    The reason is that Opera's .innerHTML doesnt return the script tag
                    as
                    <script src="/TopNavBar/sm_topnav.js">
                    but as
                    <script src='http://.../TopNavBar/sm_topnav.js'>
                    That is, it gives single quotes. The script matches on double quotes,
                    so it fails.

                    You can either fix the script to test for either " or ', or you could
                    drop it and hardcode the value of the "loc" variable. I recommend
                    the latter, otherwise you are just waiting for the next browser quirk
                    to come and bite you in the ***.

                    /L
                    --
                    Lasse Reichstein Nielsen - lrn@hotpop.com
                    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
                    'Faith without judgement merely degrades the spirit divine.'

                    Comment

                    • -DRB-

                      #11
                      Re: Opening Window with Javascript problem...

                      Ok.... I've now got that delightful 'out of my depth' feeling last
                      felt about 10 years ago in one particular course that made my head
                      swim...

                      Easy bit: I can easily lose the clock though the guy I'm writing this
                      for would like one if poss. Any recommendations ?

                      Harder bit: I used JPerk to design the menu systems in the page...
                      yep, I know I should be learning about this and hard coding it myself
                      but I am an amateur trying to do a friend a favour...! I've been
                      looking at the page in Netscape and there's an odd gap between the
                      frames. I thought I'd designed the table in the top frame on a pixel
                      basis so that I could set the height of the top frame and know it
                      would look ok on different browsers. That has failed in Netscape
                      though... and based on current evidence I bet you know why!

                      As for what you said below.... once again I'm going to have to sit
                      down and try to get to grips with this... yikes... and I'm away for
                      the next 5 days so if you get no response that's not equating to being
                      ignored,

                      I've just downloaded Mozilla and I'll get hold of Opera too.

                      Thanks,

                      Dave.



                      On 13 Aug 2003 21:04:45 +0200, Lasse Reichstein Nielsen
                      <lrn@hotpop.com > wrote:
                      [color=blue]
                      >-DRB- <bog@bog.com> writes:
                      >[color=green]
                      >> Oh bunch of arse, this just gets better and better :-)
                      >>
                      >> What browser are you working with...? *sigh*[/color]
                      >
                      >Opera 7.2beta 3 (w/ Proximitron as proxy).
                      >
                      >In Mozilla FB 0.6 I have to scroll the buttons into view in the
                      >topmost frame. Otherwise it seems to work.
                      >
                      >Looking at the code, a few things spring to my eyes:
                      >The digital clock script checks for the presence of either
                      > document.layers or document.all . That means that it will fail
                      >in Mozilla, which has neither.
                      >
                      >This tag: "<script menumaker>" looks pretty odd. I guess the
                      >"menumaker" is just misplaced and the type attribute missing.
                      >The content of that script is just a document.write that writes
                      >another script tag. That is wasteful.
                      >
                      >
                      >As far as I can see, the image for the menu is
                      > <URL:http://www.btinternet. com/~david.boggitt/TopNavBar/sm_topnav_b1.gi f>
                      >Opera does not have the "TopNavBar/" part of the URL.
                      >That part is found by the part of the script that initializes the "loc"
                      >variable:
                      >---
                      >if (typeof(loc)==" undefined" || loc==""){
                      > var loc=""
                      > if (document.body& &document.body. innerHTML){
                      > var tt = document.body.i nnerHTML.toLowe rCase();
                      > var last = tt.indexOf("sm_ topnav.js\"");
                      > if (last>0){
                      > var first = tt.lastIndexOf( "\"", last);
                      > if (first>0 && first<last)
                      > loc = document.body.i nnerHTML.substr (first+1,last-first-1);
                      > }
                      > }
                      >}
                      >---
                      >Apart from having the innerHTML computed three times (and this is before
                      >the page is completely loaded), it is a pretty fragile way of finding
                      >the location of the script.
                      >
                      >It is supposed to find this part:
                      > src="TopNavBar/sm_topnav.js"
                      >and let loc="TopNavBar/". It fails silently in Opera.
                      >The reason is that Opera's .innerHTML doesnt return the script tag
                      >as
                      > <script src="/TopNavBar/sm_topnav.js">
                      >but as
                      > <script src='http://.../TopNavBar/sm_topnav.js'>
                      >That is, it gives single quotes. The script matches on double quotes,
                      >so it fails.
                      >
                      >You can either fix the script to test for either " or ', or you could
                      >drop it and hardcode the value of the "loc" variable. I recommend
                      >the latter, otherwise you are just waiting for the next browser quirk
                      >to come and bite you in the ***.
                      >
                      >/L[/color]

                      Comment

                      Working...