How to name the 1st window ?

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

    #1

    How to name the 1st window ?

    Hi,

    I have a big main window, prepared in html, and a small one, opened by
    window.open in <script> in main window script.
    I would like to click in small one and open sth in main one. How to do it?

    There is "target", but how to traget the 1st window?

    Thanks,
    Peter

  • Stuart Palmer

    #2
    Re: How to name the 1st window ?

    window.opener

    "Piotr" <piotrpl@info.c om.pl> wrote in message
    news:cd36ki$6u3 $1@news.onet.pl ...[color=blue]
    > Hi,
    >
    > I have a big main window, prepared in html, and a small one, opened by
    > window.open in <script> in main window script.
    > I would like to click in small one and open sth in main one. How to do it?
    >
    > There is "target", but how to traget the 1st window?
    >
    > Thanks,
    > Peter
    >[/color]


    Comment

    • DU

      #3
      Re: How to name the 1st window ?

      Piotr wrote:[color=blue]
      > Hi,
      >
      > I have a big main window,[/color]

      Big main window is often referred as opener. Also parent window.

      prepared in html, and a small one,

      Often referred as secondary window, or child window or sub-window (best
      technical term, IMO) or popup window.

      opened by[color=blue]
      > window.open in <script> in main window script.[/color]

      Make sure you hold, keep a window object reference to that sub-window.
      This is highly useful in scripts creating sub-windows; you may want to
      re-use, recycle that sub-window or just be able to bring it back in
      front of the opener. The general idea is, e.g.

      <script type="text/javascript">
      var WindowObjectRef erence;
      function OpenRequestedPo pup(strUrl, strTarget)
      {
      if(WindowObject Reference == null || WindowObjectRef erence.closed)
      /*
      if the sub-window does not exist or if it was closed, then create it
      */
      {
      WindowObjectRef erence = window.open(str Url, strTarget,
      "resizable,stat us,scrollbars,t op=100,left=250 ,width=400,heig ht=300"
      }
      else
      /*
      else just bring the sub-window back in front of the opener
      */
      {
      WindowObjectRef erence.focus();
      };
      }
      </script>

      And in the html:

      <p><a href="path/MyGarden.html" target="ANewSub Window"
      onclick="OpenRe questedPopup(th is.href, this.target); return false;"
      title="Clicking this link will create a new separate window">See my
      garden</a></p>
      [color=blue]
      > I would like to click in small one and open sth in main one. How to do it?
      >[/color]

      Giving an url showing what you have done so far and what are your files
      is always more convenient.
      [color=blue]
      > There is "target", but how to traget the 1st window?
      >[/color]

      target is primarly used to target a frame or a sub-window from the opener.
      [color=blue]
      > Thanks,
      > Peter
      >[/color]

      In the sub-window, add this:
      <p><button type="button" onclick="if(ope ner)
      {opener.locatio n.href='path/filename.html'; };">Load filename in
      opener</button></p>


      http://msdn.microsoft.com/workshop/a...ies/opener.asp

      The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.


      http://msdn.microsoft.com/workshop/a...ods/open_0.asp



      DU

      Comment

      • Ivo

        #4
        Re: How to name the 1st window ?

        "Piotr" <piotrpl@info.c om.pl> wrote in message
        news:cd36ki$6u3 $1@news.onet.pl ...[color=blue]
        > Hi,
        >
        > I have a big main window, prepared in html, and a small one, opened by
        > window.open in <script> in main window script.
        > I would like to click in small one and open sth in main one. How to do it?
        >
        > There is "target", but how to traget the 1st window?
        >
        > Thanks,
        > Peter[/color]

        This line of script will attch a name to the current window:
        top.name="mainw in";
        You can add this to the script in the main window and any links in the popup
        with target="mainwin " will open in the main window. This way you don't need
        script in the popup. You can also refer to the main window from the popup
        with "opener". This line of script in the popup:
        opener.location .href="nextpage .html";
        will open a new page in the opener, regardless of whether or not has a name.
        HTH
        Ivo


        Comment

        • Piotr

          #5
          Re: How to name the 1st window ?

          Finally I used <A HREF="javascrip t:window.opener .location.href= blabla>

          Thank you very much!

          Peter

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: How to name the 1st window ?

            Piotr wrote:[color=blue]
            > Finally I used <A HREF="javascrip t:window.opener .location.href= blabla>[/color]

            That's nonsense, see the FAQ and <http://validator.w3.or g/>.
            Use

            <script type="text/javascript">
            function setOpenerLoc(sU RI)
            {
            if (window.opener
            && !window.opener. closed
            && typeof window.opener.l ocation != "undefined" )
            {
            window.opener.l ocation = sURI;
            }
            return false;
            }
            </script>

            <a href="#"
            onclick="return setOpenerLoc('b labla');"[color=blue]
            >...</a>[/color]

            instead. It would be better if you also wrote that link dynamically so
            that users without script support do not encounter "malfunctioning " links:

            <script type="text/javascript">
            // ...

            document.write(
            '<a href="javascrip t:void(setOpene rLoc(\'blabla\' ))"'
            + ' onclick="return setOpenerLoc(\' blabla\');">'
            + '...'
            + '<\/a>');
            </script>


            PointedEars

            Comment

            Working...