Create a Link to use as a Bookmarklet

[Total: 0    Average: 0/5]

This shows how to have a url dynmically created on your page to be used as a bookmarklet.

Head Code:

	<SCRIPT LANGUAGE="JavaScript">
<!--

var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;

function display(id, str) {
  if (NS4) {
    with (document[id].document) {
      open();
      write(str);
      close();
    }
  } else {
    document.all[id].innerHTML = str;
  }
}

function noEntry() {
  alert("Please enter the desired code for the bookmark.");
}

function updateLink(form) {
  if (!NS4 && !IE4) return;

  var bmname = form.bmname.value;
  var jscode = form.jscode.value;
  var contactname = form.contactname.value;
  var contactemail = form.contactemail.value;
  var linkcode = "<A HREF='' NAME='bmlink'>" + bmname + "</A>";
  display("bookmark", linkcode);
  var jslink = (NS4) ? document.bookmark.document.links[0] : document.all.bmlink;
  jslink.href = 
"javascript:Q='';if(top.frames.length==0)Q=document.getSelection();void(btw=window.open('"+jscode+"?db=links&add_form=1&URL='+escape(location.href)+'&Title='+escape(document.title)+'&Description='+escape(Q)+'&Contact%20Name="+escape(contactname)+"&Contact%20Email="+contactemail+"','AddToLinks','menubar=1,location=1,resizable=1,scrollbars=1,status=1,toolbar=1'));btw.focus();";
}

// -->
</SCRIPT>

Body Code:

<h1>"Template" for Netscape bookmarklet for add.cgi</h1>
This would work in IE, but there is a better way, but this will work in both.


<p>Explain what this is .... bla bla bla</p>

<form>
Enter the desired name of the bookmark (the button):<br>

<!-- You might want to edit the value field -->
<INPUT NAME="bmname" VALUE="Add to YourSite" SIZE ="50">

<!-- You must change the path to your add.cgi -->
<input type="hidden" name="jscode" value="http://www.yoursite.com/links/add.cgi"><br><br>
<!-- no more changes needed in the form -->

Enter your name:<br>
<INPUT NAME="contactname" VALUE="Editor name" SIZE="50" MAXLENGTH="255"><br><br>
Enter your email address:<br>
<INPUT NAME="contactemail" VALUE="Editor's email" SIZE="50" MAXLENGTH="255"><br><br>
<INPUT TYPE="button" VALUE="Update" onClick="updateLink(this.form)">&nbsp;&nbsp;
<SPAN ID="bookmark" STYLE="POSITION: absolute; left:200; top:400"><U>the bookmark code will show here</U></SPAN>
</form>
</p>

Times Viewed: 7

Leave a Reply

Your email address will not be published. Required fields are marked *