javascript rookie needs a close-window button

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

    javascript rookie needs a close-window button

    OK. I am halfway decent with HTML. Now I want to try javascript for some
    things that HTML cannot do. I have looked over a tutorial & all.

    What I want to do is create a button, that when pressed, closes the window
    it is in, and launches a URL. The window the button is in is actually just
    a sub-page of the main website page, launched with target="blank", but I
    just do not want to close the window as I said, I want to launch a website
    address from it & have the launched from window close.

    So please, walk me through this. Where do I place the:

    <SCRIPT language="JavaS cript"> ?

    (Oh - this is thr right way, correct - case sensitive, right?)

    Then what? I can create a button with the tutorials, but if you know, just
    write the darned thing for me please - I learned HTML mostly from
    copy/pasting.

    AND... OK, now more complicated maybe (???). Actually this is more
    important than the above. This is from an application sub-page, the page
    opening with target="_blank" . So the below is HTML that creates buttons.
    If the applicant presses the "submit application" button, at least when I
    press it, it launches O.E. and asks me if I want to send the filled-in text
    through O.E. to the email recipient. You know what I mean, right ? Well,
    I want the window the "submit application" button is in to do it's thing all
    right - submitting through the email, but I also want the page or window
    (I.E. or other?) launched from to close also.

    ------------ the HTML code that shows two buttons:

    <input type="submit" value="submit application">
    <input type="reset" value="start over"/><br>

    Thanks for your input. Assume I know nothing about javascript, but can get
    around in HTML.

    ...D.
  • Yann-Erwan Perio

    #2
    Re: javascript rookie needs a close-window button

    ....D. wrote:
    [color=blue]
    > What I want to do is create a button, that when pressed, closes the window
    > it is in, and launches a URL. The window the button is in is actually just
    > a sub-page of the main website page, launched with target="blank", but I
    > just do not want to close the window as I said, I want to launch a website
    > address from it & have the launched from window close.[/color]

    In the popup, you can refer to the opener window with the property
    "opener"; before closing your popup, you just have to set the
    location.href property of the opener to the new location.

    Add the following in your popup:

    ---
    <script type="text/javascript">
    //write the close button
    //but only if it can be used successfully
    if(opener && self.close) {
    document.write(
    "<input type='button' "+
    "value='Clo se' "+
    "onclick='" +
    "opener.locatio n.href=\"http://jibbering.com/faq/\";"+
    "self.close();" +
    "'"+
    ">"
    );
    }
    </script>
    ---
    [color=blue]
    > <SCRIPT language="JavaS cript"> ?
    >
    > (Oh - this is thr right way, correct - case sensitive, right?)[/color]

    Javascript is indeed case-sensitive, however the HTML attribute language
    is not - and it's actually deprecated, so don't use it, use
    type="text/javascript" instead.
    [color=blue]
    > If the applicant presses the "submit application" button, at least when I
    > press it, it launches O.E. and asks me if I want to send the filled-in text
    > through O.E. to the email recipient.[/color]

    That's just a "mailto:user@do main.com" action for the form. However the
    technique changes a bit from above:

    ---
    <script type="text/javascript">
    function validate(frm){
    if(opener) {
    opener.location .href="http://jibbering.com/faq/";
    }
    if(window.close ) {
    setTimeout("win dow.close()",1) ;
    }
    return true;
    }
    </script>

    <form action="mailto: foo@bar.com"
    onsubmit="retur n validate(this)" >
    <input type="text" name="foo">
    <input type="submit">
    </form>
    ---

    Note that the techniques exposed, while maybe acceptable for a personal
    website, would not be used for a commercial one, since they have too
    many inherent flaws:
    - they rely on popup window, which can be affected by popup-blocking
    software,
    - they rely on mailto:, assuming that the user has a mail agent
    configured (which is not always the case, many people just use web-based
    mail agents) - ideally the mail should be built and sent server-side
    (google for formmail).


    HTH
    Yep.

    Comment

    • Andrew Thompson

      #3
      Re: javascript rookie needs a close-window button

      On Fri, 17 Sep 2004 22:15:51 -0700, ...D. wrote:
      [color=blue]
      > OK. I am halfway decent with HTML. Now I want to try javascript for some
      > things that HTML cannot do.[/color]

      Really? What things?
      [color=blue]
      >..I have looked over a tutorial & all.[/color]

      Well, you have put in the hard yards..
      Did you *read* *it*, or just glance
      over it?
      [color=blue]
      > What I want to do is create a button, that when pressed, closes the window
      > it is in, and launches a URL.[/color]

      Pop-Ups.. Your app. is already sunk.

      They do work, OK, in some browsers, but
      whoever deploys such broken methods must
      take special pains to explain to browsers
      why your links are not doing anything in
      there wonderfully current and up to date
      IE with SP 2.

      ....[color=blue]
      > So please, walk me through this. Where do I place the:
      >
      > <SCRIPT language="JavaS cript"> ?[/color]

      Somewhere late last millennium.
      <script type='text/javascript'>

      You can define functions in the <head>
      and call them in the <body>. Actually
      you can define methods all over the place,
      but it makles most sense to collect them
      in one place, either in the <head>, or
      in an external file.
      [color=blue]
      > (Oh - this is thr right way, correct - case sensitive, right?)[/color]

      No. JS is generally not case sensitive.

      Now, ..given I've been up 28 hours, I better
      leave the important stuff for the gurus.

      Over and ..snore..

      --
      Andrew Thompson
      http://www.PhySci.org/codes/ Web & IT Help
      http://www.PhySci.org/ Open-source software suite
      http://www.1point1C.org/ Science & Technology
      http://www.lensescapes.com/ Images that escape the mundane

      Comment

      • Randy Webb

        #4
        Re: javascript rookie needs a close-window button

        Andrew Thompson wrote:
        [color=blue]
        > On Fri, 17 Sep 2004 22:15:51 -0700, ...D. wrote:[/color]

        <--snip-->
        [color=blue][color=green]
        >>(Oh - this is thr right way, correct - case sensitive, right?)[/color]
        >
        >
        > No. JS is generally not case sensitive.
        >
        > Now, ..given I've been up 28 hours, I better
        > leave the important stuff for the gurus.[/color]

        Blame it on the lack of sleep. JS is very case-sensitive. Its the HTML
        tags that are not. :-)


        --
        Randy
        comp.lang.javas cript FAQ - http://jibbering.com/faq

        Comment

        • Andrew Thompson

          #5
          Re: javascript rookie needs a close-window button

          On Sat, 18 Sep 2004 14:04:48 -0400, Randy Webb wrote:
          [color=blue][color=green]
          >> No. JS is generally not case sensitive.[/color][/color]
          ...[color=blue]
          > ..JS is very case-sensitive. Its the HTML
          > tags that are not. :-)[/color]

          Aha! Thank you. Personally I allways
          use correct case with JS commands (as
          well as I understand the nomenclature)
          and string comparisons, for the simple
          reason it becomes easier for me to read.

          Lucky for me (and the OP) you were paying
          attention. ;-)

          --
          Andrew Thompson
          http://www.PhySci.org/codes/ Web & IT Help
          http://www.PhySci.org/ Open-source software suite
          http://www.1point1C.org/ Science & Technology
          http://www.lensescapes.com/ Images that escape the mundane

          Comment

          Working...