newbie help

N

Nom DePlume

Hi,

I'm new to scripting so bear with me...

I copied this script directly from a MS website. It's supposed to open
the Add to Favorites window when you click on the text. Trouble is, I
keep getting an "Unterminated string constant" error, and I don't quite
know how to fix it. Also, nothing is showing on the page, yet I still
get the error. Could I get a little help please? Thanks. Here's the
code:

<SCRIPT>
<!--
if ((navigator.appVersion.indexOf("MSIE") > 0)
&& (parseInt(navigator.appVersion) >= 4)) {
document.write("<U><SPAN STYLE='color:blue;cursor:hand;'
onclick='window.external.
AddFavorite(location.href, document.title);'>
Add this page to your favorites</SPAN></U>");
}
//-->
</SCRIPT>
 
R

Randy Webb

Nom said:
Hi,

I'm new to scripting so bear with me...

I copied this script directly from a MS website. It's supposed to open
the Add to Favorites window when you click on the text. Trouble is, I
keep getting an "Unterminated string constant" error, and I don't quite
know how to fix it. Also, nothing is showing on the page, yet I still
get the error. Could I get a little help please? Thanks. Here's the
code:

<SCRIPT>


Not needed any longer.
if ((navigator.appVersion.indexOf("MSIE") > 0)
&& (parseInt(navigator.appVersion) >= 4)) {

My Opera passes that test, in some modes, its utterly useless for
determining my browser. As does my AOL browser, neither of which will
support what you are trying to do.

document.write("<U><SPAN STYLE='color:blue;cursor:hand;'
onclick='window.external.
AddFavorite(location.href, document.title);'>

The above two lines should all be on one line.
Add this page to your favorites</SPAN></U>");
}
//-->

Not needed.
</SCRIPT>

All in all, the script is utter junk.
 
N

Nom DePlume

: Nom DePlume wrote:
: > Hi,
: >
: > I'm new to scripting so bear with me...
: >
: > I copied this script directly from a MS website. It's supposed to
open
: > the Add to Favorites window when you click on the text. Trouble is,
I
: > keep getting an "Unterminated string constant" error, and I don't
quite
: > know how to fix it. Also, nothing is showing on the page, yet I
still
: > get the error. Could I get a little help please? Thanks. Here's the
: > code:
: >
: > <SCRIPT>
:
: <script type="text/javascript">
:
: > <!--
:
: Not needed any longer.
:
: > if ((navigator.appVersion.indexOf("MSIE") > 0)
: > && (parseInt(navigator.appVersion) >= 4)) {
:
: My Opera passes that test, in some modes, its utterly useless for
: determining my browser. As does my AOL browser, neither of which will
: support what you are trying to do.
:
:
: > document.write("<U><SPAN STYLE='color:blue;cursor:hand;'
: > onclick='window.external.
: > AddFavorite(location.href, document.title);'>
:
: The above two lines should all be on one line.
:
: > Add this page to your favorites</SPAN></U>");
: > }
: > //-->
:
: Not needed.
:
: > </SCRIPT>
:
: All in all, the script is utter junk.
:

thanks for your reply. I can see I have a lot to learn. Without getting
overly complicated, what would be a better way to write this?

Dave


: --
: Randy
: Chance Favors The Prepared Mind
: comp.lang.javascript FAQ - http://jibbering.com/faq/
:
 
R

Randy Webb

Nom said:
: Nom DePlume wrote:
: > Hi,
: >

thanks for your reply. I can see I have a lot to learn. Without getting
overly complicated, what would be a better way to write this?

A better way? Not write it at all. Seriously, put up a link to "How to
bookmark this page" and on the other page, explain how to do it in the
different browsers. It has been discussed here until most people are
tired of discussing it, because there is no reliable way to detect
whether the browser supports the window.external.addFavorite method as
you can't directly test for it.
 
M

Michael Winter

I copied this script directly from a MS website. It's supposed to open
the Add to Favorites window when you click on the text. Trouble is, I
keep getting an "Unterminated string constant" error, and I don't quite
know how to fix it. Also, nothing is showing on the page, yet I still
get the error.

<SCRIPT>
<!--
if ((navigator.appVersion.indexOf("MSIE") > 0)
&& (parseInt(navigator.appVersion) >= 4)) {
document.write("<U><SPAN STYLE='color:blue;cursor:hand;'
onclick='window.external.
AddFavorite(location.href, document.title);'>
Add this page to your favorites</SPAN></U>");
}
//-->
</SCRIPT>

A slightly better way to write this would be:

In HEAD (or an external style sheet):

<style type="text/css">
span.fake-link {
background: #ffffff;
color: #0000ff;
cursor: hand;
text-decoration: underline;
}
</style>


In BODY:

<script type="text/javascript">
if( window.external ) {
var favouriteText = '<span class="fake-link"\n' +
'onclick="window.external.AddFavorite(window.location,' +
'document.title)">Add this page to your favourites<\/span>';
document.write( favouriteText );
}
</script>

Notice the differences

- I replaced your style rule with a class. If you only intend to use that
style once, you might want to alter it to an id selector.
- I added a background colour to the rule. If you start specifying
colours, you should specify all colours. Most importantly, make sure that
foreground colours will be on appropriate background colours. If you've
already done this elsewhere, that's fine.
- I removed the U element, and replaced it with the appropriate CSS
declaration.
- The compatibility testing is no longer performed with the unreliable
user-agent string. It is now done with feature testing. Out of four
browsers on my system, only IE will add that SPAN element. Really, the
feature test should include an explicit check for
window.external.AddFavorite, but such a check actually returns false in
IE, even though calling the method succeeds.

Hope that helps,
Mike
 
N

Nom DePlume

Randy,

Thank you for time. For now, I will drop the whole thing, and play with
it at a later time

Dave

: Nom DePlume wrote:
: > : > : Nom DePlume wrote:
: > : > Hi,
: > : >
:
: <--snip-->
:
: >
: > thanks for your reply. I can see I have a lot to learn. Without
getting
: > overly complicated, what would be a better way to write this?
: >
:
: A better way? Not write it at all. Seriously, put up a link to "How to
: bookmark this page" and on the other page, explain how to do it in the

[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top