View Full Version : Basic question - unable to find syntax documentation

Chris Cormier
05-11-2007, 02:24 PM
There is a bit of Java script that I am using, I find it works in Internet Explorer but not firefox, the code is :

(window.open("...", "foobar", "...") || window).focus();

I'm not sure what the double | character does, what the window keyword does when used after it, and I have spent some time looking for information on how that syntax works. Sorry for such a newbie question...

05-11-2007, 02:36 PM
what do you actually need?

Chris Cormier
05-11-2007, 02:41 PM
Again, I need to know what that syntax means. The use of the "||" operator, the use of the window keyword. Because it's not working in Firefox though it is in IE, and there is likely some minor syntax adjustment I need to make. And also, I just want to know what the syntax means so I can use it elsewhere if need be.

05-11-2007, 02:47 PM
Yes I understand that you don't know what || means, and I don't understand why you are using some code, which you don't know how it works.. :) that's why I am asking you what you need to do..

I think you need open some window... window.open("...", "foobar", "...") is okay lets say.. || is logical operator and it means OR. I can't say more until I will see all that code..

Chris Cormier
05-11-2007, 03:37 PM
I know that "||" means a logical OR in just about any other syntax I've seen it in. It seems to do some kind of object dereferencing in this case, but the syntax is strange to me. I am learning this on-the-job. I know you probably find it strange that I could be employed to work without being completely knowledgable in every respect to every aspect of programming Javascript. I have worked in IT for 25 years so they must think I can pick it up as I go (and I'm glad for the chance to update my skills). THAT'S why I'm using code where I have an idea what it is doing, but have some questions on the specifics. (In a year from now when the contract is over I'll have learned plenty, and likely look at what I designed, and how some things were structured, and cringe in embarrassment, right now the focus is just getting something done.)

I have a window.open statement that works fine, but the popup window wasn't always getting the focus. I googled around to find some solution, and this was the only one that worked. Basically if my window open statement (which works fine) is X, the syntax is (X||window).focus(). But it doesn't work in Firefox, so I figure it's some minor difference in how those browsers process the script, that is causing the problem. (For instance, yesterday I tracked down a problem to the fact that firefox allows spaces in the second parameter of window.open, but IE will skwawk about that syntax).

The actual code is :

popupScript = "<script language='javascript'>" & _
"(window.open('" & moveUp & "Utilities/AVValues.aspx?ctl=" & e.PostBackValue & _
"','Values','width=400, height=300, menubar=yes, resizable=no')||window).focus();" & _
Page.RegisterClientScriptBlock("AVValuesPopupScript", popupScript)

Where e.postbackvalue is a string, with 6-10 alphabetic characters and no spaces. right now moveUp is an empty string 90% of the time, and contains "../" the other 10%.

05-11-2007, 04:08 PM
Noone knows everything, so I don't find it strange..

I don't know, what about use that script just without that "||window" I mean just "menubar=yes, resizable=no').focus()";

Chris Cormier
05-11-2007, 05:05 PM
That works in IE too, I'll use that syntax as it's simpler. Still doesn't work in properly in Firefox. Thing is, the popup window is already open when this gets called, the second parameter in open() being the same, causes it to re-use the same window (which I want) and refresh its contents, but it stays behind the main window (which I don't want).

Thanks for the help.

p.s. not SURE if the second parameter being the same is what makes it grab the same window again, but it is in fact grabbing the same window, and it's a reasonable assumption. I could make the window a dialog box or something that would not let the user click on the main window till it was closed, but I don't particularly want that.

05-11-2007, 05:19 PM
It's really strange... anyway.. you can use div instead of popup if you want, just make a div with display:none, position:absolute, create a iframe within that div, load content into iframe, and when you will need to display the "popup" set display:block.. and some coordinates (left,top) it's a alternative ;)

05-11-2007, 09:06 PM
All that syntax means is that if the window.open succeeds it is equivalent to:

window.open("...", "foobar", "...").focus();

If the window.open fails it is equivalent to:


Basically it is testing the success of the open and setting the focus one of two ways based on whether the first OR second value is true. Since the second value (window) is always true it will always set one or the other.

05-11-2007, 09:49 PM
If it's not working in Firefox, then check the Javascript Console to see if it throws any error.

05-12-2007, 01:41 AM
I thought that you were wondering why you had to include window. Its because there are so many different parts of javascript that they split them up by using different categories like:
And others

Hope I helped,