How can I use window.open to Open a page in the center of screen?

C

Clare Hsiao

Hi,everybody:

How can I use window.open to Open a page in the center of screen?

I know showModalDialog() can,but I have to run both in IE and NN, so I
have to use window.open to open a new page.

Is ther any help?
Thanks a lot.
 
R

Rob

Clare Hsiao said:
Hi,everybody:

How can I use window.open to Open a page in the center of screen?

I know showModalDialog() can,but I have to run both in IE and NN, so I
have to use window.open to open a new page.

Is ther any help?
Thanks a lot.

1) Find out the width and height of the screen,
2) Nowing the height and width of the window you want to open calculate the
top and the left for the new window:

function centerWindow(){

win_height=400;
win_width=500;
win_top=(screen.availHeight-win_height)/2;
win_left=(screen.availWidth-win_width)/2;

url='http://www.google.com';
name='';
features="width="+win_width+", height="+win_height+", top="+win_top+",
left="+win_left;
//alert(features);
return window.open(url,name,features);
}
 
R

Randy Webb

Bluelava said:
in javascript,strings are always put between two ""
such
url="http://www.google.com"
if url='http://www.google.com'
some error will happen.

Total bull.

myString = 'Some text in single quotations';
myOtherString = "My other string with double quotations";

myThirdString = 'My Third string with a \'single quoted\' quote in it';

The only requirement is that you escape " inside " and ' inside '.
 
M

Michael Winter

in javascript,strings are always put between two ""
such
url="http://www.google.com"
if url='http://www.google.com'
some error will happen.

Are you trying to say that only double quotation marks can be used as
string delimiters? If so, you are wrong. From the Netscape JavaScript
Reference (v1.5), Part 1, Chapter 1 - String[1]:

"A string can be represented as a literal enclosed by single or
double quotation marks; for example, "Netscape" or `Netscape'."

Mike


[1] I would check ECMA-262, but I don't have Acrobat installed at the
moment. With such a simple matter, there should be no difference.
 
L

Lasse Reichstein Nielsen

Bluelava said:
in javascript,strings are always put between two ""
such
url="http://www.google.com"
if url='http://www.google.com'
some error will happen.

No. In Javascript, string literals can be wrapped in either singel or
double quotes. That is,
'foo bar'
and
"foo bar"
are equivalent.

I personally prefer the latter because it won't give problems when
writing English, like "it won't give problems". The "'" inside would
have to be escaped when using single quotes: 'it won\'t give problems'.

But both are equally correct, and no error will happen from the above
example.

/l
 
L

Lasse Reichstein Nielsen

Michael Winter said:
From the Netscape JavaScript Reference (v1.5), Part 1, Chapter 1 -
String[1]:

"A string can be represented as a literal enclosed by single or
double quotation marks; for example, "Netscape" or `Netscape'."

Which is accidentally a bad example, because the singel quote before
the second "Netscape" is not the correct character :)
[1] I would check ECMA-262, but I don't have Acrobat installed at the
moment. With such a simple matter, there should be no difference.

For completeness:
 
M

Michael Winter

Michael Winter said:
From the Netscape JavaScript Reference (v1.5), Part 1, Chapter 1 -
String[1]:

"A string can be represented as a literal enclosed by single or
double quotation marks; for example, "Netscape" or `Netscape'."

Which is accidentally a bad example, because the singel quote before
the second "Netscape" is not the correct character :)

Very good spotting (*applauds Mr Nielsen*). I'm sure it appeared as an
apostrophe character, not a left single quote on the web page - checks -
no, it doesn't. My fault, but I'm surprised they did that.
[1] I would check ECMA-262, but I don't have Acrobat installed at the
moment. With such a simple matter, there should be no difference.

For completeness:
---
StringLiteral ::
" DoubleStringCharacters_opt "
' SingleStringCharacters_opt '
---

Thank you for looking that up. This is new machine I've built and it's not
quite up to speed yet.

Mike
 
B

bengee

Rob said:
It is even recommended when used in a html string. Because HTML makes have
use of double quoted strings we can use something like:

<a herf="" onclick="alert('hallo');">hallo</a>

I thought that single or double quotes could be used in HTML? So you
could have :-

<a href='' onclick='alert("hallo");'>hallo</a>


bengee
 
M

Michael Winter

I thought that single or double quotes could be used in HTML? So you
could have :-

<a href='' onclick='alert("hallo");'>hallo</a>

You can use either, as long as the paired quotes are of the same type. I
think it's simply convention that double quotes are used in HTML, nothing
more.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top