By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,276 Members | 1,951 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,276 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Rob

"Clare Hsiao" <cl*********@hotmail.com> schreef in bericht
news:40*********************@news.frii.net...
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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


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);
}
Jul 20 '05 #2

P: n/a
in javascript,strings are always put between two ""
such
url="http://www.google.com"
if url='http://www.google.com'
some error will happen.
Jul 20 '05 #3

P: n/a
Bluelava wrote:
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 '.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4

P: n/a
On Tue, 10 Feb 2004 20:59:36 +0800, Bluelava <li******@tom.com> wrote:
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.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #5

P: n/a
Bluelava <li******@tom.com> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6

P: n/a
Michael Winter <M.******@blueyonder.co.invalid> writes:
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:
---
StringLiteral ::
" DoubleStringCharacters_opt "
' SingleStringCharacters_opt '
---

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7

P: n/a
On Tue, 10 Feb 2004 20:25:59 +0100, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
Michael Winter <M.******@blueyonder.co.invalid> writes:
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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #8

P: n/a
Rob

"Bluelava" <li******@tom.com> schreef in bericht
news:39********************************@4ax.com...
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 your wrong. Both can be used.

Rob
Jul 20 '05 #9

P: n/a
Rob

"Bluelava" <li******@tom.com> schreef in bericht
news:39********************************@4ax.com...
in javascript,strings are always put between two ""
such
url="http://www.google.com"
if url='http://www.google.com'
some error will happen.


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>

Rob
Jul 20 '05 #10

P: n/a
Rob wrote:
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
Jul 20 '05 #11

P: n/a
On Fri, 13 Feb 2004 08:27:56 +0000, bengee
<po********@localhost.localdomain> wrote:
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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.