"Dummy" JavaScript variable -- possible?

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

    "Dummy" JavaScript variable -- possible?

    All,

    I'm looking for a way to define a "dummy" variable in JavaScript;
    specifically for the window object. I would like to define a window
    object that would normally be generated with window.open() but not
    actually open a new window.

    E.g.: normal code could look something like this:
    aVar = window.open("ht tp://www.someurl.com ", ...);
    aVar.location = "http://www.newlocation .com/";
    document.write( "made it here OK");

    If I remove the aVar = window.open(... line then aVar.location will
    fail and the rest of the script breaks - "made it here OK" will not be
    printed, etc.

    I would liek to do something like this:
    vVar = create_dummy_wi ndow; // does not open a window
    aVar.location = "http://www.newlocation .com/"; // this should now not
    break & the rest of the script should now be OK.
    document.write( "made it here OK"); // should be printed this time

    Is this possible? Any ideas here?

    Thanks,

    Bryan Ashby
  • Evertjan.

    #2
    Re: "Dummy&quo t; JavaScript variable -- possible?

    Bryan Ashby wrote on 25 nov 2003 in comp.lang.javas cript:
    [color=blue]
    > I would liek to do something like this:
    > vVar = create_dummy_wi ndow; // does not open a window
    > aVar.location = "http://www.newlocation .com/"; // this should now not
    > break & the rest of the script should now be OK.
    > document.write( "made it here OK"); // should be printed this time
    >
    > Is this possible? Any ideas here?[/color]

    Easy:

    <script>
    vVar = new window();
    aVar.location = "http://www.newlocation .com/";
    document.write( "made it here OK");
    </script>










    No, not possible. ;-}

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Michael Winter

      #3
      Re: &quot;Dummy&quo t; JavaScript variable -- possible?

      Bryan Ashby wrote on 25 Nov 2003:

      <snipped description>
      [color=blue]
      > Is this possible? Any ideas here?[/color]

      You could create an object that mimics the window object, but that
      would be quite a task. Whether naming that object, 'window', is
      allowable, and whether it would hide and override the original
      object, are different questions altogether.

      Mike

      --
      Michael Winter
      M.Winter@blueyo nder.co.uk.invalid (remove ".invalid" to reply)

      Comment

      • Evertjan.

        #4
        Re: &quot;Dummy&quo t; JavaScript variable -- possible?

        Michael Winter wrote on 25 nov 2003 in comp.lang.javas cript:
        [color=blue]
        > Bryan Ashby wrote on 25 Nov 2003:
        >
        > <snipped description>
        >[color=green]
        >> Is this possible? Any ideas here?[/color]
        >
        > You could create an object that mimics the window object, but that
        > would be quite a task. Whether naming that object, 'window', is
        > allowable, and whether it would hide and override the original
        > object, are different questions altogether.[/color]

        You could name it "Window".


        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: &quot;Dummy&quo t; JavaScript variable -- possible?

          bryanashby@hotm ail.com (Bryan Ashby) writes:
          [color=blue]
          > I'm looking for a way to define a "dummy" variable in JavaScript;
          > specifically for the window object. I would like to define a window
          > object that would normally be generated with window.open() but not
          > actually open a new window.[/color]

          Why a window object then. I.e., why not just any object.
          [color=blue]
          > E.g.: normal code could look something like this:
          > aVar = window.open("ht tp://www.someurl.com ", ...);
          > aVar.location = "http://www.newlocation .com/";
          > document.write( "made it here OK");
          >
          > If I remove the aVar = window.open(... line then aVar.location will
          > fail and the rest of the script breaks - "made it here OK" will not be
          > printed, etc.[/color]

          Yes.
          [color=blue]
          > I would liek to do something like this:
          > vVar = create_dummy_wi ndow; // does not open a window[/color]

          Try
          var vVar = {};
          It is equivalent to
          var vVar = new Object();
          [color=blue]
          > aVar.location = "http://www.newlocation .com/"; // this should now not
          > break & the rest of the script should now be OK.[/color]

          You can assign to the location property of any object. It's just in
          windows objects that it does something.
          [color=blue]
          > document.write( "made it here OK"); // should be printed this time[/color]

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Richard Cornford

            #6
            Re: &quot;Dummy&quo t; JavaScript variable -- possible?

            "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
            news:Xns943ED3E 8C85D5eejj99@19 4.109.133.29...
            <snip>[color=blue][color=green]
            >>You could create an object that mimics the window object,
            >>but that would be quite a task. Whether naming that object,
            >>'window', is allowable, and whether it would hide and override
            >>the original object, are different questions altogether.[/color]
            >
            > You could name it "Window".[/color]

            Gecko browsers have a global function property with the name "Window"
            (the window constructor) and probably would not like having it replaced.
            I don't like the suggestion of - vVar = new window(); - in your other
            post much either as "window" is a reference to the current window object
            and not a function, so conforming ECMA Script implementations should be
            expected to throw a TypeError exception at that line.

            It sounds to me like the OP wants a general (I assume that assigning to
            the location is just an example, else Lasse's response fits the
            requirement) window impersonating object that will act as a sink for any
            subsequent window interaction. That probably cannot be done 100% but
            these objects:-

            function WindowDummy(url ){
            this.self = (this.window = (this.parent =
            (this.frames = (this.top = this))));
            this.opener = window;
            this.open = window.open;
            this.closed = false;
            this.location = new LocationDummy(u rl);
            this.document = new DocumentDummy(t his.location);
            this.length = 0;
            this.focus = forDummys;
            this.close = function(){this .closed = true;};
            this.navigator = window.navigato r;
            this.resizeTo = (this.resizeBy = (this.moveBy =
            (this.moveTo = forDummys)));
            }
            function LocationDummy(u rl){
            this.href = url;
            this.toString = function(){retu rn this.href;};
            this.refresh = (this.replace = forDummys);
            }
            function DocumentDummy(l oc){
            this.location = loc;
            this.body = this.documentEl ement = {};
            this.close = (this.open = (this.write = (this.writeln = forDummys)));
            this.links = (this.anchors = (this.forms = (this.images = [])));
            }
            var forDummys = function(){retu rn;};

            -have a reasonable go at it (and could be added to).

            Richard.


            Comment

            • Evertjan.

              #7
              Re: &quot;Dummy&quo t; JavaScript variable -- possible?

              Richard Cornford wrote on 25 nov 2003 in comp.lang.javas cript:
              [color=blue]
              > I don't like the suggestion of - vVar = new window(); - in your other
              > post much either as[/color]

              While it "felt" kind of good, that started as a joke.
              [color=blue]
              > this.self = (this.window = (this.parent =
              > (this.frames = (this.top = this))));[/color]

              Do we need al those () ?
              Parsing will bubble to the right anyway, IMHO ?

              this.self=this. window=this.par ent=this.frames =this.top=this;

              --
              Evertjan.
              The Netherlands.
              (Please change the x'es to dots in my emailaddress)

              Comment

              • Bryan Ashby

                #8
                Re: &quot;Dummy&quo t; JavaScript variable -- possible?

                Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<ekvwz0cg. fsf@hotpop.com> ...
                [color=blue]
                > Why a window object then. I.e., why not just any object.[/color]

                I am writing a "JavaScript proxy" of sorts; preventing popups/etc. One
                of the problems I have had is removing a variable and the rest of the
                script breaks.
                [color=blue]
                > Try
                > var vVar = {};
                > It is equivalent to
                > var vVar = new Object();[/color]

                This works great!

                [color=blue]
                > You can assign to the location property of any object. It's just in
                > windows objects that it does something.
                >[/color]

                That's fine. The only thing I'm looking for here is to be able to
                remove (well actually replace a variable line) (e.g.: aVar =
                window.open(... ) -> var aVar = {};) and not have the rest of the
                script "terminate"

                Bryan

                Comment

                • Richard Cornford

                  #9
                  Re: &quot;Dummy&quo t; JavaScript variable -- possible?

                  "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
                  news:Xns943EDEE 7EFBBFeejj99@19 4.109.133.29...[color=blue][color=green]
                  >>I don't like the suggestion of - vVar = new window(); - in
                  >>your other post much either as[/color]
                  >
                  >While it "felt" kind of good, that started as a joke.[/color]

                  Sorry, when I scrolled your post down to the large blank space I assumed
                  that I had got to the end of it, if I had kept going I would have seen
                  the indicator that it was humorous.
                  [color=blue][color=green]
                  >> this.self = (this.window = (this.parent =
                  >> (this.frames = (this.top = this))));[/color]
                  >
                  >Do we need al those () ?
                  >Parsing will bubble to the right anyway, IMHO ?
                  >
                  >this.self=this .window=this.pa rent=this.frame s=this.top=this ;[/color]

                  They are not needed, but neither are LF/CR pairs to separate statements
                  or tabs and spaces to indent blocks. Some things get into source code
                  for the benefit of human readers instead of machine interpreters.

                  Richard.


                  Comment

                  • Richard Cornford

                    #10
                    Re: &quot;Dummy&quo t; JavaScript variable -- possible?

                    "Bryan Ashby" <bryanashby@hot mail.com> wrote in message
                    news:17658c4e.0 311251432.4f7ae 917@posting.goo gle.com...
                    <snip>[color=blue]
                    >I am writing a "JavaScript proxy" of sorts; preventing popups/etc.
                    >One of the problems I have had is removing a variable and the rest
                    >of the script breaks.[/color]

                    I guessed that this was your plan. You should have a look at a recent
                    thread with the subject "Hi, stupid popup question" (2003-11-12) because
                    Yann-Erwan Perio has demonstrated that proxy based pop-up blocking can
                    be entirely circumvented. Which might be grounds to reconsider putting
                    any effort into writing one if pop-up blocking is the main intention.
                    [color=blue][color=green]
                    > > Try
                    > > var vVar = {};
                    > > It is equivalent to
                    > > var vVar = new Object();[/color]
                    >
                    > This works great![/color]

                    It would work fine with the simple case of assigning a value to the
                    location property of the new window. But don't you need a more general
                    solution to deal with other common cross-window interaction scripts? It
                    is fairly common, for example, for scripts to assign values to the
                    location.href property (though not recommended over assuaging to the
                    location property). Calling the resizeTo and moveTo method of the new
                    window is also common (also not recommended) as is writing contents into
                    new windows with - vVar.document.w rite(" ... ") -.
                    [color=blue][color=green]
                    >> You can assign to the location property of any object. It's just in
                    >> windows objects that it does something.[/color]
                    >
                    >That's fine. The only thing I'm looking for here is to be able to
                    >remove (well actually replace a variable line) (e.g.: aVar =
                    >window.open(.. .) -> var aVar = {};) and not have the rest of the
                    >script "terminate"[/color]

                    And:-

                    var vVar = window['open'](...);
                    -or-
                    var vVar = window['op'+'en'](...);
                    -or-
                    var x = 'open';
                    var vVar = this[x](...);
                    -or-
                    var document = window;
                    var vVar = document.open(. ..);

                    - or any other of the many possible methods of calling the window.open
                    function without needing to write the string "window.ope n" onto the
                    source code? Unfortunately, the people who are most likely to obscure
                    the window.open call in the code are also the people who's pop-ups most
                    deserve to be blocked.

                    Richard.


                    Comment

                    Working...