473,395 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

jcript to book,ark page

I'm fairly new to javascript so please forgive my errors. I want to
put a statement on a web page to let the user bookmark the page. I've
seen several different versions of this - but I can't make mine work
in IE. Here is the code:
<script language="JavaScript" type="text/javascript">
<!--
function cknav(){
var IEstring = "<a
href='javascript:window.external.addFavorite('http ://la.fooweb.com','LA
Homepage')";
IEstring += "><\/a>" ;
// IEstring += ";' title='Add to Favorites '><\/a>" ;
// IEstring += "(location.href,document.title);' title='Add to
Favorites'>Favorites<\/a>" ;
var NSstring = "Click [Ctrl + D] ";
var OPstring = "Click [Ctrl + T]";
var NSOPstring = "by returning to the main page and "
var OTHstring = "Bookmark this page!"
var whichString = OTHstring ;
var agt = navigator.userAgent.toLowerCase();
var app = navigator.appName.toLowerCase();
var ieAgent = agt.indexOf('msie');
var nsAgent = app.indexOf('netscape');
var opAgent = app.indexOf('opera');
// How do I get IE to execute this ?? it doesn't seem to do
anything.
if (ieAgent!= -1) { whichString = IEstring;
document.write(whichString);
alert(whichString) }
else if (nsAgent!= -1){ whichString += NSOPstring + NSstring;
alert(whichString) }
else if (opAgent!= -1){whichString += NSOPstring + OPstring;
alert(whichString) }
}
-->
</SCRIPT>

</head>

<body>
<table width="80%" frame="border" cellspacing="3" cellpadding="3"
border="4" bgcolor="#ffffff" align="center" summary="Statement">
<tbody><tr>
<td>
<br />
<!-- Try One - IE only , gives an eror -->
<h1 class="c1"><font size="+2" color="#ff0000"><b>New Web
Address.</b></font><br /><br />
<font size="+1" color="#000000"> If you got here by the
http://nu.net/lanet link, you were redirected the NEW home
of LA http://la.fooweb.com. <U>
<span style='color:red;cursor:hand;'>
<a
href="javascript:window.external.AddFavorites('HTT P://URL.COM','SITENAME')">Bookmark
Me</a>
</span></u>
<!-- Try 2 - Great for non IE but need to know how to make IE do the
bookmark in the script -->
<br />
<h1 class="c1"><font size="+2" color="#ff0000"><b>New Web
Address.</b></font><br /><br />
<font size="+1" color="#000000"> If you got here by the
http://nu.net/lanet link, you were redirected the NEW home
of LA <a
href="http://la.fooweb.com">http://la.fooweb.com</a>. <U>
<span style='color:red;cursor:hand;'
onClick=cknav()>Bookmark this address.</span></u>
</font><br />
</h1>
</td>
</tr>
</tbody>
</table><!-- End of page content -->
</body>
</html>

TIA
Stephen
Jul 23 '05 #1
3 1365
Seen wrote:
I'm fairly new to javascript so please forgive my errors. I want to
put a statement on a web page to let the user bookmark the page. I've
seen several different versions of this - but I can't make mine work
in IE. Here is the code:
<script language="JavaScript" type="text/javascript">
The language attribute on script tags has been depreciated, just use
type.
<!--
There is no need to hide scripts, don't bother.

function cknav(){
var IEstring = "<a
href='javascript:window.external.addFavorite('http ://la.fooweb.com','LA
Homepage')";
IEstring += "><\/a>" ;
Your quotes seem unbalanced, but I can't test right now. Also, there
appears to be no text between the <a ...></a> tags, so even if it does
work and you do create a link in the page, you likely can't see it
anyway. And I think the capitalisation of "addFavorite" should be
"AddFavorite".

Try:

var IEstring = "<a href=\"javascript:window.external.AddFavorite('"
+ "http://la.fooweb.com','LA Homepage')\""
+ ">Click to add LA Homepage to your favourites<\/a>";

Adding "links" this way is considered an improper use of the <a> tag,
which should load new content. Why not just use a button?

[...]

Why bother with all the browser detection?

Have you considered writing help text to the page, and if you detect
that AddFavorite is going to work, replace the text with a button that
will add the link?

In the HTML put:

<span id="addBookmarkText" class="someClass">To add a
bookmark for this page in IE or Netscape, press Ctrl+D.
If you are using Opera, press Ctrl+T</span>

Then lower in the page (or fired from an onload) put:

<script type="text/javascript">
if (window.external.AddFavorite) {
if (document.getElementById) {
var ele = document.getElementById("addBookmarkText");
} else {
var ele = document.all["addBookmarkText"];
}
var eStr = "<button "
+ "onclick=\"window.external.AddFavorite(...);\" "
+ ">Add page to favorites<\/button>";
ele.innerHTML = eStr;
}
</script>

Now any browser that supports AddFavorite() can take advantage of it.
And if MS stops supporting it, the button won't appear.

Again, untested as I don't have IE right now.

[...] <h1 class="c1"><font size="+2" color="#ff0000"><b>New Web


Using <h1> this way is not how it's intended to be used. I don't know
what you've defined in the class c1, however it seems that you are
completely redefining the h1 tag, so why use it? Just put the
appropriate attributes in the c1 class, or add them inline with
style="...".

<font> has been depreciated for years, use something like:

<p class="c1">New Web ... </p>

or

<p class="c1"><span style="font-size: 120%; color: #ff0000;
font-weight: bold;">New Web ... </span> ... </p>

Hope that helps.
--
Fred
Jul 23 '05 #2
Fred Oz wrote:
Seen wrote: [...]

OK, had time to test this in IE now. Small fix:
Then lower in the page (or fired from an onload) put:

<script type="text/javascript">
if (window.external.AddFavorite) {
Can't test AddFavorite like this, presumably because it is calling an
IE function rather than a JScript function. It would have been nice if
MS had supported the ability to test it though. So test
window.external and hope that if it's implemented, so is AddFavorite:

if (window.external) {

[...] var eStr = "<button "
+ "onclick=\"window.external.AddFavorite(...);\" "
+ ">Add page to favorites<\/button>";
Is better written as:

var eStr = "<button "
+ "onclick=\"window.external.AddFavorite('"
+ document.location
+ "','"
+ document.title
+ "');\""
+ ">Add page to favorites<\/button>";
ele.innerHTML = eStr;


I'm also making the bold assumption that if the browser has so far
supported AddFavorite and window.external (and maybe document.all too),
it will support innerHTML.

Some people object to innerHTML, but using a Microsoft invented script
extension to enable an MS IE-only API seems apt...
--
Fred
Jul 23 '05 #3
"Fred Oz" <Oz****@iinet.net.auau> wrote in message
news:Jg*****************@news.optus.net.au...
Fred Oz wrote:
Seen wrote:

[...]

OK, had time to test this in IE now. Small fix:
Then lower in the page (or fired from an onload) put:

<script type="text/javascript">
if (window.external.AddFavorite) {


Can't test AddFavorite like this, presumably because it is calling an
IE function rather than a JScript function. It would have been nice
if
MS had supported the ability to test it though. So test
window.external and hope that if it's implemented, so is AddFavorite:

if (window.external) {


An alternate way to test for this is:

if (window.external && 'unknown' == typeof window.external.AddFavorite)
{
alert('AddFavorite supported');
}
else
{
alert('AddFavorite not supported');
}

Even if an unsupporting browser has window.external defined, it's almost
impossible for window.external to have an AddFavorite property that is
typeof "unknown" using user code (although the browser DOM itself could
certainly set this up and then fail to support AddFavorite anyway).

Then again, it's entirely possible Microsoft will change the behaviour
of AddFavorite in some future version of the DOM to return typeof
"object", which would mean a modification of the above code.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Kari Laitinen | last post by:
I have written a computer programming book that uses C++. The book is for beginners in the field of computer programming, but it might give useful ideas also for more experienced programmers....
4
by: dotNetDave | last post by:
About three weeks ago I released the first .NET coding standards book titled "VSDN Tips & Tricks .NET Coding Standards". Here is what the famous author/ speaker Deborah Kurata says about it: ...
15
by: ben | last post by:
this programme from sedgewick's 'algorithms in c parts 1-4' "is a sample client program that ... uses a symbol table to find the distinct values in a sequence of keys (randomly generated or read...
12
by: Guido Mureddu | last post by:
Hello, I'm a student in electronic engineering. I do know you've seen and answered this sort of topic/request countless times, but I haven't found past threads as helpful as I had hoped, and...
2
by: Paul | last post by:
Hi I am trying to run a simple windows authentication example in the Microsoft web apps book page 372 and in the page load sub I am getting the errors, name spnAuthenticated not declared,...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
25
by: Elizabeth | last post by:
Can you all give me your best recommendation(s) for books on AJAX ? Thanks ... - E -
3
by: provowallis | last post by:
I'm new to this board so I hope this reqest isn't out of line, but I'm looking for some general advice about creating links in online books. If the link target didn't involve PIs I don't think I'd...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.