Jules Manson
12-24-2005, 03:29 PM
Dear good people:
I am new to forums so please forgive me if I sound dry and matter-of-fact. After all programming is a very dry discipline but one that bring many rewards. I am self-taught at client-side scripting and I still have a lot to learn but my ego is usually too big to ask for help however sometimes we all need to put our ego aside. I have searched every corner and under every rock on the web looking for a solution before coming here. I recieved help from others at other sites however it did not solve this problem because they did not bother to test their own solutions or simply because I did not understand their responses. If you do wish to help me please test my code and your own solution before replying. Below I post the HTML and script to use as a template.
[WHAT DOES WORK AND COAUTHOR CREDIT GIVEN FOR BEST SOLUTION]
Unobtrusive DOM Scripting (http://domscripting.webstandards.org/?page_id=2) is not a new phenomena however like AJAX it has now just started to take hold among professionals. Currently no bookmark script exists that I know of that is unobtrusive and will automatically grab the URL and Title off a web page. This script does that however it is still "buggy" (see my requests for help). Once this script is debugged I will post it at several well known web sites and Dynamic Drive if they accept it. I will of course give coauthor credit along with a link to their web site for the best solution given.
[REQUEST FOR HELP - SHORT VERSION]
I want the code in this bookmark1.html (http://members.aol.com/oysteinramfjord/bookmark1.html) to behave like this bookmark2.html (http://members.aol.com/oysteinramfjord/bookmark2.html) without adding any javascript inside any tags whatsoever. All javascript must exist inside the head section of the HTML file. Both were tested with Firefox 1.5 and MSIE 6.0 with Windows Me (yes I know I am laughing too). It is more important for this script to work on MSIE. Thank you for considering this problem.
[REQUEST FOR HELP - LONG VERSION]
On both MSIE 6.0 and Firefox 1.5 the script does not wait for the onClick event to activate. On MSIE the bookmark dialog box opens immediately when the page loads. On Firefox one gets the alert message for nonsupporting browsers. Firefox is supposed to support bookmarking via scripts. Both are supposed to wait for an onClick mouse event. My intent in writing this as I did is to completely seperate behavior from structure and presentation. My goal is to eventually link this script externally via a javascript library file. It is more important for this script to work on MSIE. Please, no solutions which require adding inline javascript to my bookmark link. I already know how to do that. The onClick event handler must be contained inside the script which resides in the head section (not the anchor tag). I need to make this unobtrusive so that nonprogrammers can easily edit the HTML. This script will also serve as a model for many other unobtrusive scripts which I have planned. Please examine and test my code to see why it is not waiting for the onClick mouse event before loading. My ultimate goal is to ensure that this cross-browser script works on MSIE, Netscape, Firefox, and Opera. Thank you for considering this problem.
[THE CODE TEMPLATE]
<HTML><HEAD>
<TITLE>UNOBTRUSIVE DOM SCRIPTING - BOOKMARK</TITLE>
<SCRIPT>
function bookFav() {
if (!document.getElementById || !document.all) /* object detection to prevent errors */
{alert("Please use your browser menu to bookmark us!");} /* alert for non-supporting browsers */
else {
var el = document.getElementById("bookmark");
myURL = window.location.href; /* gets url of page to bookmark */
myTitle = document.title; /* gets title of page */
el.onClick = addFav(myURL,myTitle); /* this event is supposed to open the bookmark dialog */
}
}
function addFav(aURL,aTitle){
if (document.all) /* is this MSIE? */
{window.external.AddFavorite(aURL,aTitle);} /* if yes then call bookmark for MSIE */
else if(window.sidebar) {window.sidebar.addPanel(aURL,aTitle,"");} /* else call bookmark for NS&FF */
return false;
}
window.onload=bookFav;
</SCRIPT>
</STYLE>
</HEAD>
<BODY>
Please <A id="bookmark" href="#">bookmark</A> this site.
</BODY>
</HTML>
I am new to forums so please forgive me if I sound dry and matter-of-fact. After all programming is a very dry discipline but one that bring many rewards. I am self-taught at client-side scripting and I still have a lot to learn but my ego is usually too big to ask for help however sometimes we all need to put our ego aside. I have searched every corner and under every rock on the web looking for a solution before coming here. I recieved help from others at other sites however it did not solve this problem because they did not bother to test their own solutions or simply because I did not understand their responses. If you do wish to help me please test my code and your own solution before replying. Below I post the HTML and script to use as a template.
[WHAT DOES WORK AND COAUTHOR CREDIT GIVEN FOR BEST SOLUTION]
Unobtrusive DOM Scripting (http://domscripting.webstandards.org/?page_id=2) is not a new phenomena however like AJAX it has now just started to take hold among professionals. Currently no bookmark script exists that I know of that is unobtrusive and will automatically grab the URL and Title off a web page. This script does that however it is still "buggy" (see my requests for help). Once this script is debugged I will post it at several well known web sites and Dynamic Drive if they accept it. I will of course give coauthor credit along with a link to their web site for the best solution given.
[REQUEST FOR HELP - SHORT VERSION]
I want the code in this bookmark1.html (http://members.aol.com/oysteinramfjord/bookmark1.html) to behave like this bookmark2.html (http://members.aol.com/oysteinramfjord/bookmark2.html) without adding any javascript inside any tags whatsoever. All javascript must exist inside the head section of the HTML file. Both were tested with Firefox 1.5 and MSIE 6.0 with Windows Me (yes I know I am laughing too). It is more important for this script to work on MSIE. Thank you for considering this problem.
[REQUEST FOR HELP - LONG VERSION]
On both MSIE 6.0 and Firefox 1.5 the script does not wait for the onClick event to activate. On MSIE the bookmark dialog box opens immediately when the page loads. On Firefox one gets the alert message for nonsupporting browsers. Firefox is supposed to support bookmarking via scripts. Both are supposed to wait for an onClick mouse event. My intent in writing this as I did is to completely seperate behavior from structure and presentation. My goal is to eventually link this script externally via a javascript library file. It is more important for this script to work on MSIE. Please, no solutions which require adding inline javascript to my bookmark link. I already know how to do that. The onClick event handler must be contained inside the script which resides in the head section (not the anchor tag). I need to make this unobtrusive so that nonprogrammers can easily edit the HTML. This script will also serve as a model for many other unobtrusive scripts which I have planned. Please examine and test my code to see why it is not waiting for the onClick mouse event before loading. My ultimate goal is to ensure that this cross-browser script works on MSIE, Netscape, Firefox, and Opera. Thank you for considering this problem.
[THE CODE TEMPLATE]
<HTML><HEAD>
<TITLE>UNOBTRUSIVE DOM SCRIPTING - BOOKMARK</TITLE>
<SCRIPT>
function bookFav() {
if (!document.getElementById || !document.all) /* object detection to prevent errors */
{alert("Please use your browser menu to bookmark us!");} /* alert for non-supporting browsers */
else {
var el = document.getElementById("bookmark");
myURL = window.location.href; /* gets url of page to bookmark */
myTitle = document.title; /* gets title of page */
el.onClick = addFav(myURL,myTitle); /* this event is supposed to open the bookmark dialog */
}
}
function addFav(aURL,aTitle){
if (document.all) /* is this MSIE? */
{window.external.AddFavorite(aURL,aTitle);} /* if yes then call bookmark for MSIE */
else if(window.sidebar) {window.sidebar.addPanel(aURL,aTitle,"");} /* else call bookmark for NS&FF */
return false;
}
window.onload=bookFav;
</SCRIPT>
</STYLE>
</HEAD>
<BODY>
Please <A id="bookmark" href="#">bookmark</A> this site.
</BODY>
</HTML>