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

old fuzzy brain trying to understand

P: n/a
What I am trying to should be everyday simple, but I just can't seem to
grasp it.

What I want to do is click a link and have that link send a URL to a
function to open a new widow of a certain size. I want to be able to use
the same function for several links. What I have so far is this in the
head

<script type="text/javascript" language="javascript">
function smallWindow(myPage) {
window.open("myPage",toolbar=0,status=0,directorie s=0,menubar=0,resizabl
e=0,dependant=1,width=400, height=300);
}

Then in the link I have in the body is

<a href="javascript:smallWindow('http://www.somepage.com')">somepage</a>

It will open a new window, but it can't find the specified page. It also
doesn't seem to be sizing to what I want. (BTW, the code is all on one
line, it's just wrapping in my news reader).

I know this should be an everyday simple thing, but I just can't seem to
get a hold on it.

thanks for any help in advance,

--
Dave
=====================
Majority sometimes only means that all the fools are on the same side.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.588 / Virus Database: 372 - Release Date: 2/13/2004
Jul 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Ivo
"Nom DePlume" <jd*@ccsispXXX.com> wrote in message
news:Qv********************@prvlb.net...
What I am trying to should be everyday simple, but I just can't seem to
grasp it.

What I want to do is click a link and have that link send a URL to a
function to open a new widow of a certain size. I want to be able to use
the same function for several links. What I have so far is this in the
head

<script type="text/javascript" language="javascript">
function smallWindow(myPage) {
window.open("myPage",toolbar=0,status=0,directorie s=0,menubar=0,resizabl
e=0,dependant=1,width=400, height=300);
}
the window.open() takes three parameters:
1. the destination url
2. name of new window (if it exists already, it will be reused, if you don't
want this, give a unique name each time or just an empty string)
3. features.
In your code see only two parameters. myPage should not be in quotes as it
is supposed a variable and not to be confused with a literal text. The
features parameter should be in quotes but is not.
<a href="javascript:smallWindow('http://www.somepage.com')">somepage</a>


Use <a href="somepage" onclick="smallWin" etc.> instead.
so that people without javascript will also get the new page (albeit in the
original window)
Also, some browsers don't understand href="javascript:" very well. See the
newsgroup FAQ: <URL: http://jibbering.com/faq/#FAQ4_24 >
HTH
Ivo

Jul 20 '05 #2

P: n/a
Nom DePlume wrote:
What I am trying to should be everyday simple, but I just can't seem to
grasp it.

What I want to do is click a link and have that link send a URL to a
function to open a new widow of a certain size. I want to be able to use
the same function for several links. What I have so far is this in the
head

<script type="text/javascript" language="javascript">
function smallWindow(myPage) {
window.open("myPage",toolbar=0,status=0,directorie s=0,menubar=0,resizabl
e=0,dependant=1,width=400, height=300);
}


Man, you're so close: Try it without the quotes around the variable:

window.open(myPage, etc.

Jul 20 '05 #3

P: n/a

"mscir" <ms***@access4less.net> wrote in message
news:10*************@corp.supernews.com...
: Nom DePlume wrote:
: > What I am trying to should be everyday simple, but I just can't seem
to
: > grasp it.
: >
: > What I want to do is click a link and have that link send a URL to a
: > function to open a new widow of a certain size. I want to be able to
use
: > the same function for several links. What I have so far is this in
the
: > head
: >
: > <script type="text/javascript" language="javascript">
: > function smallWindow(myPage) {
: >
window.open("myPage",toolbar=0,status=0,directorie s=0,menubar=0,resizabl
: > e=0,dependant=1,width=400, height=300);
: > }
:
: Man, you're so close: Try it without the quotes around the variable:
:
: window.open(myPage, etc.

Tried that, but it didnt seem to make a difference.

Dave
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.588 / Virus Database: 372 - Release Date: 2/13/2004
Jul 20 '05 #4

P: n/a

"Ivo" <no@thank.you> wrote in message
news:40***********************@news.wanadoo.nl...
: "Nom DePlume" <jd*@ccsispXXX.com> wrote in message
: news:Qv********************@prvlb.net...
: > What I am trying to should be everyday simple, but I just can't seem
to
: > grasp it.
: >
: > What I want to do is click a link and have that link send a URL to a
: > function to open a new widow of a certain size. I want to be able to
use
: > the same function for several links. What I have so far is this in
the
: > head
: >
: > <script type="text/javascript" language="javascript">
: > function smallWindow(myPage) {
: >
window.open("myPage",toolbar=0,status=0,directorie s=0,menubar=0,resizabl
: > e=0,dependant=1,width=400, height=300);
: > }
:
: the window.open() takes three parameters:
: 1. the destination url
: 2. name of new window (if it exists already, it will be reused, if you
don't
: want this, give a unique name each time or just an empty string)

Empty string.. I hadn't thought of doing that.

: 3. features.
: In your code see only two parameters. myPage should not be in quotes
as it
: is supposed a variable and not to be confused with a literal text. The
: features parameter should be in quotes but is not.
:
: > <a
href="javascript:smallWindow('http://www.somepage.com')">somepage</a>
:
: Use <a href="somepage" onclick="smallWin" etc.> instead.
: so that people without javascript will also get the new page (albeit
in the
: original window)

I think this is the part that is getting me confused. shouldn't the
onclick call to the function also include the URL? Otherwise it won't
know what page I want. that way I can use it for different links and
different pages. No?

: Also, some browsers don't understand href="javascript:" very well. See
the
: newsgroup FAQ: <URL: http://jibbering.com/faq/#FAQ4_24 >

Thanks for this. I'm burning it into my eyeballs now. :)

Dave
: HTH
: Ivo
:
:
:
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.588 / Virus Database: 372 - Release Date: 2/13/2004
Jul 20 '05 #5

P: n/a
Ivo
"Nom DePlume" <jd*@ccsispXXX.com> wrote in message
news:Qp********************@prvlb.net...

"Ivo" <no@thank.you> wrote in message
news:40***********************@news.wanadoo.nl...
: "Nom DePlume" <jd*@ccsispXXX.com> wrote in message
: news:Qv********************@prvlb.net...
: > <a
href="javascript:smallWindow('http://www.somepage.com')">somepage</a>
:
: Use <a href="somepage" onclick="smallWin" etc.> instead.
: so that people without javascript will also get the new page (albeit
in the
: original window)

I think this is the part that is getting me confused. shouldn't the
onclick call to the function also include the URL? Otherwise it won't
know what page I want. that way I can use it for different links and
Sorry, I was short there. We must pass the url with the function call, and
generate a return value of false in order to prevent the href from being
followed (that 's for the javascript-impaired remember). This can be done by
writing "return false" after the function call, but with the explicit return
in the function itself (last line) we can do it like this:
<a href=""
onclick="return smallWindow( 'http://www.somepage.com' );"Here</a>


and the script:
<script type="text/javascript">
function smallWindow(myPage) {
window.open(
myPage ,
"myWindowName",
"resizable,dependant,width=400, height=300" );
return false;
}

It may be on one line if you prefer :)
If you specify don't a features parameter, all toolbars etc. are turned on,
but if you specify only one item, everything is turned off by default.
Knowing this, it is sufficient just to mention the things you want enabled.
The "dependant" thing is Netscape-only I believe. You had "resizable" set to
0 but as you see I have included it because I see no reason why you would
that to your user. It takes up no space and only those that try to resize
will notice it, and be p*d to notice they can't. If you think otherwise, by
all means remove the word from the list.
HTH
Ivo

Jul 20 '05 #6

P: n/a
Ivo
"Nom DePlume" <jd*@ccsispXXX.com> wrote in message
news:Qp********************@prvlb.net...

"Ivo" <no@thank.you> wrote in message
news:40***********************@news.wanadoo.nl...
: "Nom DePlume" <jd*@ccsispXXX.com> wrote in message
: news:Qv********************@prvlb.net...
: > <a
href="javascript:smallWindow('http://www.somepage.com')">somepage</a>
:
: Use <a href="somepage" onclick="smallWin" etc.> instead.
: so that people without javascript will also get the new page (albeit
in the
: original window)

I think this is the part that is getting me confused. shouldn't the
onclick call to the function also include the URL? Otherwise it won't
know what page I want. that way I can use it for different links and
Sorry, I was short there. We must pass the url with the function call, and
generate a return value of false in order to prevent the href from being
followed (that 's for the javascript-impaired remember). This can be done by
writing "return false" after the function call, but with the explicit return
in the function itself (last line) we can do it like this:
<a href=""
onclick="return smallWindow( 'http://www.somepage.com' );"Here</a>


and the script:
<script type="text/javascript">
function smallWindow(myPage) {
window.open(
myPage ,
"myWindowName",
"resizable,dependant,width=400, height=300" );
return false;
}

It may be on one line if you prefer :)
If you specify don't a features parameter, all toolbars etc. are turned on,
but if you specify only one item, everything is turned off by default.
Knowing this, it is sufficient just to mention the things you want enabled.
The "dependant" thing is Netscape-only I believe. You had "resizable" set to
0 but as you see I have included it because I see no reason why you would
that to your user. It takes up no space and only those that try to resize
will notice it, and be p*d to notice they can't. If you think otherwise, by
all means remove the word from the list.
HTH
Ivo

Jul 20 '05 #7

P: n/a
On Fri, 27 Feb 2004 03:01:43 -0500, Nom DePlume <jd*@ccsispXXX.com> wrote:

[snip]
<script type="text/javascript" language="javascript">
The language attribute is deprecated - remove it. The type attribute is
sufficient.
function smallWindow(myPage) {
window.open("myPage",toolbar=0,status=0,directorie s=0,menubar=0,resizabl
e=0,dependant=1,width=400, height=300);
}
As you have already been shown in this thread, the function call should
look more like:

window.open(myPage,'target','dependent,width=400,h eight=300');

where 'target' contains the name of the new window (more on this later).

Also notice the difference in the features string:

1) You spelt dependent incorrectly
2) Disabled features have been omitted
3) There are no spaces between the feature names (spaces aren't allowed in
the string)

Regarding the second point: if boolean features are omitted, they default
to off. This means you don't have to disable every option you don't intend
to use. You can further abbreviate the string by only including the name
of the feature; dependent and dependent=1 are equivalent.
Then in the link I have in the body is

<a href="javascript:smallWindow('http://www.somepage.com')">somepage</a>
[snip]

Ivo already pointed you to the FAQ section that comments on the JavaScript
pseudo-protocol. You should have read that the preferred format for the
element would be:

<a href="http://www.somepage.com/"
onclick="smallWindow('http://www.somepage.com/');return false"somepage</a>
You'll notice repetition there. You can shorten this to:

<a href="http://www.somepage.com/"
onclick="smallWindow(this.href);return false"somepage</a>
where this.href will evaluate to the string, "http://www.somepage.com/".

Finally, I noticed that you didn't like the idea of having to explicitly
specify a target name in the smallWindow() function as it adversely
affected the reusability. This doesn't have to be so: just pass in the
target name, as the following demonstrates:

function smallWindow( url, target ) {
return window.open( url, target, 'dependent,width=400,height=300');
}
...
<a href="http://www.somepage.com/"
onclick="smallWindow(this.href,'somepage');return false"somepage</a>


Mike

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

P: n/a
Ivo wrote:
<snip>
... we can do it like this: <a href=""
onclick="return smallWindow( 'http://www.somepage.com' );"
Here</a>

<snip>

Now you have lost the fall-back of having a real URL in the HREF. Better
might be:-

<a href="http://example.com" onclick="return smallWindow(this.href);">
Something a bit more meaningful than &quot;Here&quot;</a>

But you haven't addressed the handling of the influence of pop-up
blocking software.

Richard.
Jul 20 '05 #9

P: n/a

"Nom DePlume" <jd*@ccsispXXX.com> wrote in message
news:Qv********************@prvlb.net...
: What I am trying to should be everyday simple, but I just can't seem
to
: grasp it.
:
[snip]

Thank you everyone!

I think I am starting to get the grasp of this idea. Maybe if I was
20-something and grew up with computers on a daily basis it would be
different, but being 50+ and not having that advantage when younger this
is all rather new to me.

thanks again to everyone, and may your scripts always be bug free!

Dave
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.588 / Virus Database: 372 - Release Date: 2/13/2004
Jul 20 '05 #10

P: n/a
If anyone is interested, the web site is http://www.lynnconstables.com.
The js I was trying to work out is on the links page. thanks to everyone
for pointing me in the right direction.

Dave

"Nom DePlume" <jd*@ccsispXXX.com> wrote in message
news:Qv********************@prvlb.net...
: What I am trying to should be everyday simple, but I just can't seem
to
: grasp it.
:
: What I want to do is click a link and have that link send a URL to a
: function to open a new widow of a certain size. I want to be able to
use
: the same function for several links. What I have so far is this in the
: head
:
: <script type="text/javascript" language="javascript">
: function smallWindow(myPage) {
:
window.open("myPage",toolbar=0,status=0,directorie s=0,menubar=0,resizabl
: e=0,dependant=1,width=400, height=300);
: }
:
: Then in the link I have in the body is
:
: <a
href="javascript:smallWindow('http://www.somepage.com')">somepage</a>
:
: It will open a new window, but it can't find the specified page. It
also
: doesn't seem to be sizing to what I want. (BTW, the code is all on one
: line, it's just wrapping in my news reader).
:
: I know this should be an everyday simple thing, but I just can't seem
to
: get a hold on it.
:
: thanks for any help in advance,
:
: --
: Dave
: =====================
: Majority sometimes only means that all the fools are on the same side.
:
:
: ---
: Outgoing mail is certified Virus Free.
: Checked by AVG anti-virus system (http://www.grisoft.com).
: Version: 6.0.588 / Virus Database: 372 - Release Date: 2/13/2004
:
:
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.588 / Virus Database: 372 - Release Date: 2/13/2004
Jul 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.