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

detecting browser

P: n/a

pls, why is this not working?

<SCRIPT language=JavaScript type="text/javascript">
var br = '<SCRIPT language=Javascript'
br += 'src="js_pop.js" type="text/javascript">'
br += '</SCRIPT>'
var op = '<SCRIPT language=Javascript'
op += 'src="js_pop-op.js" type="text/javascript">'
op += '</SCRIPT>'
if (navigator.userAgent.indexOf('Opera') != -1 ) {
document.write(op)
} else {
document.write(br)
}
//-->
</SCRIPT>

I pulled a script with an identical construction from the JS Bible:

function reWrite() {
var newContent = “<HTML><HEAD><TITLE>A New Doc</TITLE></HEAD>”
newContent += “<BODY BGCOLOR=’aqua’><H1>This document is brand new.</H1>”
newContent += “Click the Back button to see original document.”
newContent += “</BODY></HTML>”
document.write(newContent)
}
what's wrong with my construction?? error msg I get in IE says
"undeterminated string constant".. and the other weird thing is that part
of the script appears at the very top of the page, this is what appears:

" var op = "
(http://www.francesdelrio.com/hbl/index2.html)
thank your for any help....

Frances
Jul 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
> pls, why is this not working?

<SCRIPT language=JavaScript type="text/javascript">
var br = '<SCRIPT language=Javascript'
br += 'src="js_pop.js" type="text/javascript">'
br += '</SCRIPT>'
var op = '<SCRIPT language=Javascript'
op += 'src="js_pop-op.js" type="text/javascript">'
op += '</SCRIPT>'
if (navigator.userAgent.indexOf('Opera') != -1 ) {
document.write(op)
} else {
document.write(br)
}
//-->
</SCRIPT>

I pulled a script with an identical construction from the JS Bible:

function reWrite() {
var newContent = “<HTML><HEAD><TITLE>A New Doc</TITLE></HEAD>”
newContent += “<BODY BGCOLOR=’aqua’><H1>This document is brand new.</H1>”
newContent += “Click the Back button to see original document.”
newContent += “</BODY></HTML>”
document.write(newContent)
}
what's wrong with my construction?? error msg I get in IE says
"undeterminated string constant".. and the other weird thing is that part
of the script appears at the very top of the page, this is what appears:

" var op = "


When the browser sees

br += '</SCRIPT>'

it stupidly thinks that </SCRIPT> is the end of the script. So what the compiler
sees is

br += '

which looks like an unterminated string constant and the rest of the script is
displayed as text. The moral of that is that you must dirty up the close script
tag so that the browser will not behave so stupidly. I recommend inserting a \
before the >. Others like to put it before the slash. I think it is better to
put it before the > because that also solves a related problem with XML CDATA.

br += '</script\>';

jslint checks for this. http://www.crockford.com/javascript/lint.html

Get rid of the //-->. It is a waste of space. The latest style is to use
lowercase in the tags.

Jul 20 '05 #2

P: n/a
"Frances Del Rio" <fd***@yahoo.com> wrote in message
news:op**************@news.cis.dfn.de...
When a web browsers finds an opening script tag like:-
<SCRIPT language=JavaScript type="text/javascript">
It has to decide how much of what follows to send to the JavaScript
interpreter. It does that by looking for - </SCRIPT> - in the HTML.
var br = '<SCRIPT language=Javascript'
br += 'src="js_pop.js" type="text/javascript">'
And it finds it here:-
br += '</SCRIPT>'


To use the closing HTML script tag in a JavaScript string you need to
make it look like something else. Using escape characters can be
effective - <\/script> - or </script\> -.

<snip>

Richard.
Jul 20 '05 #3

P: n/a
On 02 Jul 2003 13:26:19 +0200, Lasse Reichstein Nielsen
<lr*@hotpop.com> wrote:
"Douglas Crockford" <no****@laserlink.net> writes:
Others like to put it before the slash. I think it is better to
put it before the > because that also solves a related problem with XML CDATA.

br += '</script\>';


The most suprising thing is that it works. According to specification,
what terminates the script content is the "end tag open", i.e., "</".


I think it works because of error correction in the browser, they see
the ETAGO, but because it's not followed by SCRIPT> then they know
it's not what the author intended.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4

P: n/a
Frances Del Rio <fd***@yahoo.com> writes:
the reason for this whole thing (which anyway was a good learning
exercise) is that Opera starts counting the screen.availWidth at the
left of the BROWSER WINDOW, not the entire screen, they way other
browsers do..
They do? It would have been great, but I don't think it is so.
I get 1600 as the value of "screen.availWidth", which is the
width of the entire screen. Since I run Opera in MDI, the entire
screen isn't "available", and anything based on the screen size
will most likely fail.
so that if you have the left panel open (where list of
e-mail folders, newsgroups, contacts, etc appear) this left panel
doesn't count towards screen.availWidth in Opera...


I see no difference between having the sidebar open or not.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5

P: n/a
I also get the right valuation for screen.availWidth in Opera (in my case
1024), but still if left panel is open window shows up further to the right
than it otherwise would.. check out

http://www.francesdelrio.com/hbl/index2.html
(scroll down & click where it says "testimonials")
(am on whatever latest version of Opera is on W98..)

I think if I found a way to center pop-ups on screen I wd run into same
problem w/Opera... thank you for yr response... Frances


On 06 Jul 2003 18:47:12 +0200, Lasse Reichstein Nielsen <lr*@hotpop.com>
wrote:
Frances Del Rio <fd***@yahoo.com> writes:
the reason for this whole thing (which anyway was a good learning
exercise) is that Opera starts counting the screen.availWidth at the
left of the BROWSER WINDOW, not the entire screen, they way other
browsers do..


They do? It would have been great, but I don't think it is so.
I get 1600 as the value of "screen.availWidth", which is the width of the
entire screen. Since I run Opera in MDI, the entire
screen isn't "available", and anything based on the screen size
will most likely fail.
so that if you have the left panel open (where list of
e-mail folders, newsgroups, contacts, etc appear) this left panel
doesn't count towards screen.availWidth in Opera...


I see no difference between having the sidebar open or not.
/L

Jul 20 '05 #6

P: n/a
"Frances Del Rio" <fd***@yahoo.com> wrote in message
news:op**************@news.cis.dfn.de...
<snip>
I think if I found a way to center pop-ups on screen I wd run
into same problem w/Opera...

<snip>

Yes you would. Opera positions new window relative to it's workspace
area and not the screen. But there are other browsers that provide less
than accurate and useful information in screen.availWidth/Height.
Currently I often find that some script authors attempt to centre a
window in Opera results in it appearing 3/4 out of the display area,
rendering its contents unreadable; the opposite of the desired effect.

This centring a window on screen idea is fatally flawed anyway, on
multi-monitor displays the rectangle representing the desktop dimensions
may not all be displayable on the available monitors and opening a
pop-up on a neighbouring monitor will not bring it to the users
attention. While opening a pop-up so it overlaps two or more monitors
will not make it easily read.

It strikes me that the sensible place to open a new window, if you want
it to immediately come to the users attention, is over the existing
window because that it where the user is looking at the moment they
trigger the action that opens the window. As the majority of browsers
will open a new window over the existing one if not asked to put it
somewhere else it would probably more reliably place a new window where
the user could see it if no position instructions were sent to the
window.open command at all.

Of course these days there is no reason to expect a call to the
window.open function to result in a new window being opened at all so
the question of where the window would have opened becomes moot.

Richard.
--

Example JavaScript DOM listings for: Opera 7.11,
Mozilla 1.2 and ICEbrowser 5.4
<URL: http://www.litotes.demon.co.uk/dom_root.html >
Jul 20 '05 #7

P: n/a
Richard Cornford wrote:
"Frances Del Rio" <fd***@yahoo.com> wrote in message
news:op**************@news.cis.dfn.de...
<snip>
I think if I found a way to center pop-ups on screen I wd run
into same problem w/Opera...
<snip>

Yes you would. Opera positions new window relative to it's workspace
area and not the screen. But there are other browsers that provide less
than accurate and useful information in screen.availWidth/Height.
Currently I often find that some script authors attempt to centre a
window in Opera results in it appearing 3/4 out of the display area,
rendering its contents unreadable; the opposite of the desired effect.


Thank you. This answers Lasse's last post in this thread....
Of course these days there is no reason to expect a call to the
window.open function to result in a new window being opened at all
excuse me????

so the question of where the window would have opened becomes moot.


thanks for yr response..... Frances
Jul 20 '05 #8

P: n/a
Richard Cornford wrote:
"Frances Del Rio" <fd***@yahoo.com> wrote in message
news:be************@ID-127847.news.dfncis.de...
<snip>
Of course these days there is no reason to expect a call to the
window.open function to result in a new window being opened at
all


excuse me????


<snip>

After being unnecessarily barraged with advertising pop-up window many
users have decided that they have had enough and have done something
about it. They either use a browser that provides them with control over
the opening of pop-up window or they use separate pop-up blocking
software. (There are also an increasing number of PDA browsers which
often cannot open new window.)


yes but wait a minute, doesn't this pop-up-blocking sw distinguish betw.
UNSOLICITED pop-ups and pop-ups that open when user clicks somewhere?
I think it's great that there is sw that blocks unsolicited pop-ups
(although to a point, there are cases when unsol. pop-ups open that are
not advertising, aren't there?) I love to use pop-ups, and know how to
do them well, have used them a lot, though not excessively; I think if
you know how to use pop-ups right you can do good UI design with them...
thank you for yr response....


Jul 20 '05 #9

P: n/a
On Tue, 08 Jul 2003 09:57:17 -0400, Frances Del Rio <fd***@yahoo.com>
wrote:
yes but wait a minute, doesn't this pop-up-blocking sw distinguish betw.
UNSOLICITED pop-ups and pop-ups that open when user clicks somewhere?
Some do, some don't...
I love to use pop-ups, and know how to
do them well, have used them a lot, though not excessively; I think if
you know how to use pop-ups right you can do good UI design with them...
thank you for yr response....


I know my don't, mine just redirect the open to the same window, or do
nothing depending on config.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #10

P: n/a
"Frances Del Rio" <fd***@yahoo.com> wrote in message
news:be************@ID-127847.news.dfncis.de...
<snip>
yes but wait a minute, doesn't this pop-up-blocking sw
distinguish betw. UNSOLICITED pop-ups and pop-ups that
open when user clicks somewhere? I think it's great that
there is sw that blocks unsolicited pop-ups (although to
a point, there are cases when unsol. pop-ups open that are
not advertising, aren't there?) I love to use pop-ups,
and know how to do them well, have used them a lot, though
not excessively; I think if you know how to use pop-ups
right you can do good UI design with them...


There are several types of pop-up blocker (and browsers offering that
option) and they have user configurable settings so how any one behaves
is largely up to the user. Content inserting/re-writing proxies work be
replacing the window.open function and in my experience can be
configured to just block in-line and onload/unload window opening but
they can also prevent all window opening (though they can also force new
URLs provided for new window to open in the current window or do things
like overriding the "features" list so any new windows have the chrome
that the user desired). The content inserting proxies that I have looked
at tended to default to blocking all new windows and required user
adjustment to get them to be more tolerant.

External pop-up killers work by detecting new instances of the browsers
and do not know anything about the actions or script that is trying to
open the window. I recently read of an external pop-up blocker that
required the user to hold down the Ctrl key if they actually wanted a
new window. Of course that would require that they knew in advance that
a link was going to try to open in a new window so they could hold Ctrl
down while they clicked it. Making an external pop-up blocker tolerant
of new window seems to involve providing it with a list of sites which
it will allow to open new window (though there are a lot of variations
on how this is done, some are "smarter" and more automated than others).

Browser pop-up blocking also varies. Mozilla allows fine grained control
over window opening and window chrome, Opera is also flexible but
Konqueror 2 and ICEBrowser only offer a blanket window.open disable
option.

For someone who does not like pop-ups they are all "unsolicited" and the
small PDA browsers that cannot open new window just cannot open new
window (as the hardware gets more capable and cheaper they will become
ever more common).

There is also tabbed browsing in an increasing number of browsers
(including embedded IEs) where a script opened pop-up might appear as a
new tab (displayed over the entire browser viewport area). That will
often make a UI that might make sense as a number of distinct window
distributed over a screen for simultaneous viewing into a very different
beast and of questionable worth.

If a web site stays within its original window it will be both reliable
and reasonably predictable (the user will often still have the option of
right clicking and opening the next page in a new window/tab if they
want anyway). Attempt to open a new window and you cannot determine the
outcome beforehand or verify what actually happened afterwards, and it
is difficult to design a UI if you cannot predict or detect the outcome
of user actions.

Richard.
Jul 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.