468,168 Members | 1,728 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,168 developers. It's quick & easy.

Need script to 'OpenWindow' or 'Spawn'

tmb
- Want to open a 2nd browser window when someone clinks a link with the link
content inside it.
- Want to control window size
- Want all tool bars so only blue bar at top shows
- Can I put my content in the blue bar?
- Only options are Minimize, Maximize or Close (top right of blue bar)

1 - What is the difference in 'OpenWindow' and 'Spawn' ??

2 - Can anyone point me to a simple script I can use... or just post one...

I Googled this and everything I find has so many strings attached and wants
me to 'join' something that it discourages me from geetting proceeding with
them.

I just want a simple script and a little coaching on how to implement this.

Can anybody please help me?

Thanks - tmb
Jul 23 '05 #1
2 1920
tmb wrote:
- Want to open a 2nd browser window when someone clinks a link with the link
content inside it.
- Want to control window size
- Want all tool bars so only blue bar at top shows
- Can I put my content in the blue bar?
- Only options are Minimize, Maximize or Close (top right of blue bar)
You can do all of the above (within limits of the user agent's abilities and
depending on whether some of the above features are excluded from what you can
achieve in a particular user agent) with the <attributes> parameter of the
window.open() method.

The only "content" you can put in the "blue bar" (more commonly called the
"titlebar", you _do_ know that it's not blue on many, many operating systems
don't you? and even on operating systems where it is blue, that can be changed
by the user) is the contents of the <title></title> tags on the new HTML page
opened in that window.
1 - What is the difference in 'OpenWindow' and 'Spawn' ??
Neither is a reserved word in Javascript, so they are probably just functions
written by Javascript authors. OpenWindow is presumably the name of some
function written by one Javascript author, Spawn is probably a function written
by another Javascript author. The difference between them would be the code
inside the functions.
2 - Can anyone point me to a simple script I can use... or just post one...
<script type="text/javascript">
function openWindow(lnk) {
if (window.open) {
return !window.open(lnk.href, lnk.target,
'width=400,height=300,resizable=1');
}

return true;
}
</script>
<!-- example usage -->
<a href="page.html" target="myNewWindow"
onclick="return openWindow(this);">Test</a>

The attributes string (3rd parameter of window.open()) is documented at:

<url:
http://devedge.netscape.com/library/...ce/frames.html
/>

Internet Explorer supports a few more attributes (but don't use them unless
you're only supporting IE):

<url:
http://msdn.microsoft.com/workshop/a...ods/open_0.asp />
I just want a simple script and a little coaching on how to implement this.


The problem with a simple script is that you are going to be unaware of the
issues involved in opening a new window. The conventional wisdom is that on the
general public Internet, opening a new window is very often the wrong choice. Go
to groups.google.com and search comp.lang.javascript for "open new window" to
see past discussions on this subject.

The way my solution is written, if Javascript is enabled, the "onclick" event
will fire and open the new window with the HREF and TARGET attributes specified
by the <A> tag. If the opening of the new window _appears_ to succeed (important
point, _appears_ to succeed, it may, in fact, not have been successful), then
the link is not followed and processing stops.

If Javascript is not enabled, or the user agent does not support window.open, or
window.open() appears to fail, then the link _is_ followed and the page will
open in a new window anyway (thanks to the TARGET attribute and subject to the
capabilities of the user agent), you just won't be able to control the size and
chrome of the new window.

But even this is not 100% guaranteed to open a new window containing your
content under every circumstance, in every user agent.

Please be aware that many, if not all, Web browsers now offer some degree of
popup blocking (they disable the ability to open new windows). If they do allow
new windows to be opened, many Web browsers can control the attributes which can
be applied to those new windows (for example, a new window may open, but it may
not be the size, or have the chrome that you requested).

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #2
tmb
Grant,

Just what I needed. Thanks.

tmb

"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:40***************@agricoreunited.com...
tmb wrote:
- Want to open a 2nd browser window when someone clinks a link with the link content inside it.
- Want to control window size
- Want all tool bars so only blue bar at top shows
- Can I put my content in the blue bar?
- Only options are Minimize, Maximize or Close (top right of blue bar)
You can do all of the above (within limits of the user agent's abilities

and depending on whether some of the above features are excluded from what you can achieve in a particular user agent) with the <attributes> parameter of the
window.open() method.

The only "content" you can put in the "blue bar" (more commonly called the
"titlebar", you _do_ know that it's not blue on many, many operating systems don't you? and even on operating systems where it is blue, that can be changed by the user) is the contents of the <title></title> tags on the new HTML page opened in that window.
1 - What is the difference in 'OpenWindow' and 'Spawn' ??
Neither is a reserved word in Javascript, so they are probably just

functions written by Javascript authors. OpenWindow is presumably the name of some
function written by one Javascript author, Spawn is probably a function written by another Javascript author. The difference between them would be the code inside the functions.
2 - Can anyone point me to a simple script I can use... or just post
one...
<script type="text/javascript">
function openWindow(lnk) {
if (window.open) {
return !window.open(lnk.href, lnk.target,
'width=400,height=300,resizable=1');
}

return true;
}
</script>
<!-- example usage -->
<a href="page.html" target="myNewWindow"
onclick="return openWindow(this);">Test</a>

The attributes string (3rd parameter of window.open()) is documented at:

<url:
http://devedge.netscape.com/library/...ce/frames.html />

Internet Explorer supports a few more attributes (but don't use them unless you're only supporting IE):

<url:
http://msdn.microsoft.com/workshop/a...ods/open_0.asp
/>
I just want a simple script and a little coaching on how to implement
this.
The problem with a simple script is that you are going to be unaware of the issues involved in opening a new window. The conventional wisdom is that on the general public Internet, opening a new window is very often the wrong choice. Go to groups.google.com and search comp.lang.javascript for "open new window" to see past discussions on this subject.

The way my solution is written, if Javascript is enabled, the "onclick" event will fire and open the new window with the HREF and TARGET attributes specified by the <A> tag. If the opening of the new window _appears_ to succeed (important point, _appears_ to succeed, it may, in fact, not have been successful), then the link is not followed and processing stops.

If Javascript is not enabled, or the user agent does not support window.open, or window.open() appears to fail, then the link _is_ followed and the page will open in a new window anyway (thanks to the TARGET attribute and subject to the capabilities of the user agent), you just won't be able to control the size and chrome of the new window.

But even this is not 100% guaranteed to open a new window containing your
content under every circumstance, in every user agent.

Please be aware that many, if not all, Web browsers now offer some degree of popup blocking (they disable the ability to open new windows). If they do allow new windows to be opened, many Web browsers can control the attributes which can be applied to those new windows (for example, a new window may open, but it may not be the size, or have the chrome that you requested).

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Kevin Cheramie | last post: by
reply views Thread by Krutibas Biswal | last post: by
2 posts views Thread by vmalhotra | last post: by
3 posts views Thread by sophie_newbie | last post: by
1 post views Thread by sophie_newbie | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.