473,563 Members | 2,709 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"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
Jul 20 '05 #1
9 7752
Bryan Ashby wrote on 25 nov 2003 in comp.lang.javas cript:
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?


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)
Jul 20 '05 #2
Bryan Ashby wrote on 25 Nov 2003:

<snipped description>
Is this possible? Any ideas here?


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.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #3
Michael Winter wrote on 25 nov 2003 in comp.lang.javas cript:
Bryan Ashby wrote on 25 Nov 2003:

<snipped description>
Is this possible? Any ideas here?


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.


You could name it "Window".
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #4
br********@hotm ail.com (Bryan Ashby) writes:
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.
Why a window object then. I.e., why not just any object.
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.
Yes.
I would liek to do something like this:
vVar = create_dummy_wi ndow; // does not open a window
Try
var vVar = {};
It is equivalent to
var vVar = new Object();
aVar.location = "http://www.newlocation .com/"; // this should now not
break & the rest of the script should now be OK.
You can assign to the location property of any object. It's just in
windows objects that it does something.
document.write( "made it here OK"); // should be printed this time


/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
"Evertjan." <ex************ **@interxnl.net > wrote in message
news:Xn******** ************@19 4.109.133.29...
<snip>
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.


You could name it "Window".


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.
Jul 20 '05 #6
Richard Cornford wrote on 25 nov 2003 in comp.lang.javas cript:
I don't like the suggestion of - vVar = new window(); - in your other
post much either as
While it "felt" kind of good, that started as a joke.
this.self = (this.window = (this.parent =
(this.frames = (this.top = this))));


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)
Jul 20 '05 #7
Lasse Reichstein Nielsen <lr*@hotpop.com > wrote in message news:<ek******* ***@hotpop.com> ...
Why a window object then. I.e., why not just any object.
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.
Try
var vVar = {};
It is equivalent to
var vVar = new Object();
This works great!

You can assign to the location property of any object. It's just in
windows objects that it does something.


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
Jul 20 '05 #8
"Evertjan." <ex************ **@interxnl.net > wrote in message
news:Xn******** ************@19 4.109.133.29...
I don't like the suggestion of - vVar = new window(); - in
your other post much either as


While it "felt" kind of good, that started as a joke.


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.
this.self = (this.window = (this.parent =
(this.frames = (this.top = this))));


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 ;


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.
Jul 20 '05 #9
"Bryan Ashby" <br********@hot mail.com> wrote in message
news:17******** *************** ***@posting.goo gle.com...
<snip>
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.


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.
Try
var vVar = {};
It is equivalent to
var vVar = new Object();


This works great!


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(" ... ") -.
You can assign to the location property of any object. It's just in
windows objects that it does something.


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"


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.
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
1967
by: Prisoner at War | last post by:
Hi, People, Is it possible to have an "empty" or "dummy" <a href***without*** the browser jumping back up the page?? I have a hyperlink that doesn't point to another document, but is used to call forth a modal window onClick (or is there another way, without text or image links, of calling forth JavaScript on user activity??). I would...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.