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

2 questions re popup code

P: n/a
Hi

i leached some code and strung together a popup i need for a page with 5
help buttons.
Now i could use 5 scripts and pre-load the values but i would rather get a
better understanding of how to pass some extra values to 1 script.

1.
<SCRIPT LANGUAGE="Javascript"><!--
function popUp(url) {
newWindow=window.open(url, 'windowNew',
width=300,height=133,status=no,toolbar=no,menubar= no,titlebar=no');
}
//--></SCRIPT>

i want to make width and height variables passed by
onMouseOver=javascript:popUp('popup1.html')

the popup's are all same width but height's vary from 100 to 300

2. is it possible to make the "popup" popup near the help icon that is
triggered by the mouseover. (i.e some kind of position relative to the
mouseover icon.)

Thanks in advance for any input

(i work mainly with cgi but find javascript has some nice features.
Javascript book by o'reilly on its way).

Mark
Jul 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Obantec Support wrote:
<SCRIPT LANGUAGE="Javascript"><!--
function popUp(url) {
newWindow=window.open(url, 'windowNew',
width=300,height=133,status=no,toolbar=no,menubar= no,titlebar=no');
}
//--></SCRIPT>
That's invalid HTML 4. The `script' Element requires the `type'
attribute, here with the value `text/javascript' (recommended).

The options within the third argument of the window.open(...)
method are not required for the most part as they are the default.
And AFAIS, either Mozilla/5.0 or IE 6.0 are ignoring `titlebar=no'
but in signed scripts.

window.open(..., ..., 'width=300,height=133');

should suffice.
i want to make width and height variables passed by
onMouseOver=javascript:popUp('popup1.html')
`javascript:' is not a URI scheme but a label
in (JavaScript) event handlers. Avoid it.
the popup's are all same width but height's vary from 100 to 300
Define additional arguments for the popUp(...) method to pass the value
of the required height and concatenate it in the options string.
2. is it possible to make the "popup" popup near the help icon that is
triggered by the mouseover. (i.e some kind of position relative to the
mouseover icon.)
It is. The options argument can contain `left' and `top' parameters to
specify the coordinates of the left top corner of the new window. Use
Google Groups to search for `cursor', we have discussed this here few
days ago.
(i work mainly with cgi but find javascript has some nice features.
JavaScript is but a programming language. Used server-side,
you can create CGI applications with it, too.
Javascript book by o'reilly on its way).


I have never found it necessary or appropriate to buy a book for learning a
programming language since there are numerous online sources (last but not
least newsgroups like this) where to get that knowledge for free and, for
the most part, more competent and up to date.
PointedEars

Jul 20 '05 #2

P: n/a
DU
Obantec Support wrote:
Hi

i leached some code and strung together a popup i need for a page with 5
help buttons.
Now i could use 5 scripts and pre-load the values but i would rather get a
better understanding of how to pass some extra values to 1 script.

1.
<SCRIPT LANGUAGE="Javascript"><!--
Language is deprecated; type has superseded language and it is both
backward and forward-compatible. So, you can not be wrong with type.
function popUp(url) {
newWindow=window.open(url, 'windowNew',
width=300,height=133,status=no,toolbar=no,menubar= no,titlebar=no');
You should make your newWindow variable declared as a global variable,
with the var keyword outside the popUp function.
As coded, you are requesting to have a secondary window to have no
statusbar, no scrollbars (if needed; that is if the content overflows
your requested dimensions), without the user being able to resize that
window and without titlebar. To sum all this: you want your secondary
window to be counter-usable and anti-accessibility to content. This can
not be recommendable. If you're imposing absolute width and height
values, the minimum would be to allow the user to resize such window and
scroll the window if content overflows your requested window dimensions.
Rigid window or crippled window can only hurt the user experience.
Best is to make such window dimensions entirely scalable, relative to
the browser viewport and not to use absolute dimensions.
}
//--></SCRIPT>

i want to make width and height variables passed by
onMouseOver=javascript:popUp('popup1.html')

Avoid the pseudo-protocol in all event attributes: this is wrong, bad
and just creates problems.
http://jibbering.com/faq/#FAQ4_24

"Don't use javascript: URLs
Using a straight http: URL will allow any browser to access the link."
http://www.rahul.net/aahz/javascript.html#remove

Top Ten Web-Design Mistakes of 2002
6. JavaScript in Links
http://www.useit.com/alertbox/20021223.html

I'm not even sure you can (or should be able to) create a secondary
window on a mouseover event. Usually, people resort to the onclick
event, not on the mouseover event.

the popup's are all same width but height's vary from 100 to 300

var WindowObjectReference ;

function OpenRequestedPopup(strUrl, windowWidth, windowHeight)
{

if(WindowObjectReference == null || WindowObjectReference.closed)
{
WindowObjectReference = window.open(strUrl, "RequestedPopup", "width="
+ windowWidth + ",height=" + windowHeight + ",resizable,scrollbars,status");
}
else
{
WindowObjectReference.focus();
};
}

(...)

<a href="path/Filename.html" target="RequestedPopup"
onclick="OpenRequestedPopup(this.href, 300, 133); return false;"
title="Clicking the link will create a new window (popup) or will re-use
an already opened one"> <img
src="http://www10.brinkster.com/doctorunclear/GRAPHICS/PNG/OpenRequestedPopup.png"
style="width:25px; height:25px;" alt="Clicking the link will create a
new window (popup) or will re-use an already opened one"> See my garden</a>

2. is it possible to make the "popup" popup near the help icon that is
triggered by the mouseover. (i.e some kind of position relative to the
mouseover icon.)
Yes, you have to compute the evt.pageX and evt.pageY for DOM 2 Event
compliant browsers (Opera 7 and Mozilla-based browsers are DOM 2 Event
and they support pageX and pageY; some browsers might not support
pageX/Y, then you would resort to compute pageXOffset and pageYOffset)
and you have to compute (event.clientX +
document.documentElement.scrollLeft; event.clientY +
document.documentElement.scrollTop) for browsers supporting window.event
like MSIE 6 for windows when triggered in standards compliant rendering
mode.
These properties (pageX/Y, clientX/Y) are relative to the event object
created on an onclick event.

Thanks in advance for any input

(i work mainly with cgi but find javascript has some nice features.
Javascript book by o'reilly on its way).

Mark


Your difficulties would have been handled a lot more easier with an url.

DU

Jul 20 '05 #3

P: n/a
Thomas 'PointedEars' Lahn hu kiteb:
Obantec Support wrote:
<SCRIPT LANGUAGE="Javascript"><!--
function popUp(url) {
newWindow=window.open(url, 'windowNew',
width=300,height=133,status=no,toolbar=no,menubar= no,titlebar=no');
}
//--></SCRIPT>


That's invalid HTML 4. The `script' Element requires the `type'
attribute, here with the value `text/javascript' (recommended).


It may well not be valid html 4. But It doesnt appear as if the OP
decalred it to be html 4, does it? Arent new browsers supposed to
gracefully accept documents written with older specifications?
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #4

P: n/a
DU wrote:
Obantec Support wrote:
1.
<SCRIPT LANGUAGE="Javascript"><!--


Language is deprecated; type has superseded language and it is both
backward and forward-compatible. So, you can not be wrong with type.


Full ACK
function popUp(url) {
newWindow=window.open(url, 'windowNew',
width=300,height=133,status=no,toolbar=no,menubar= no,titlebar=no');


You should make your newWindow variable declared as a global variable,
with the var keyword outside the popUp function.


Why do you find it necessary here? As the Core Reference states, variables
declared within functions without the `var' keyword are declared global.
PointedEars

Jul 20 '05 #5

P: n/a
"Thomas 'PointedEars' Lahn" <Po*********@web.de> wrote in message
news:bo*************@ID-107532.news.uni-berlin.de...
<snip>
You should make your newWindow variable declared as a global
variable, with the var keyword outside the popUp function.


Why do you find it necessary here? As the Core Reference
states, variables declared within functions without the `var'
keyword are declared global.


At least one good reason for explicitly declaring global variables by
using the var keyword in a global context is to make the source code
unambiguous. Presented with an identifier used in a function body that
will be resolved as a global variable it would be reasonable to question
whether that is deliberate or just a mistake (as seems very common). If
that identifier corresponds with a global var expression the ambiguity
is resolved, and similarly, if global var declarations are found for
other global variables and the identifier in question is not present it
become more reasonable to assume that it is a mistake. Perhaps that is
just a maintenance and team working issue, but it still seems like a
good idea to me.

However, a type-converting test on an unqualified global identifier will
succeed if the identifier has been globally declared with var but never
assigned a value, which means that code that checks to see if the window
is open before it has been opened will be able to test with -
if(newWindow) -. Otherwise, if the function that opens the window
effectively creates the global property by assigning a value to a
non-local identifier that is not globally declared with var, then
testing for that property would require either a typeof test or a
type-converting test on a property accessor instead of the identifier.

Richard.
Jul 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.