Hi,
I am using this script which is nearly working correctly, but not quite!
When a user selects some text from the web-page and copies it,
the script is supposed to pick up the current web-page url and create a
resource box or credit line that is added to the selected text when the
data is pasted.
You will see that the meta keywords are used (randomly) as the anchor text
and this should be wrapped with the href= tags in order to create a link. Thats the bit that is not workink, but I can not see why. Here is the complete script. - function init(){
-
-
// Options:
-
var useMetaKeyword = true; // Otherwise, page title
-
var minLength = 40; // Min selection chars
-
var useMetaAuthor = true; // Otherwise use domain
-
var addLinks = true; // Otherwise, just cite at end
-
var skip = new Array("home","link","click here"); // Don't link these (lowercase!)
-
-
function D(b,a,c){
-
if(b.addEventListener)b.addEventListener(a,c,false);
-
else b.attachEvent&&b.attachEvent("on"+a,c)}
-
-
function o(b,a){
-
if(typeof b=="undefined"||b==null||!RegExp)return false;
-
a=new RegExp("(^|\\s)"+a+"(\\s|$)");
-
if(typeof b=="string")return a.test(b);
-
else if(typeof b=="object"&&b.className)return a.test(b.className);return false}
-
-
function E(b,a){
-
var c=false,j;
-
for(j=b.parentNode;j!=undefined;){
-
if(b.parentNode==e.body)break;
-
else if(b.parentNode==a){c=true;break}j=j.parentNode}return c}
-
-
function F(b){
-
return b.replace(/^\s*/,"")
-
}
-
-
function G(b){
-
return b.replace(/\s*$/,"")
-
}
-
-
function H(b){
-
return G(F(b))
-
}
-
-
var I=new Array("home","link","click here"),
-
e=document,
-
x=window,
-
t=e.getElementsByTagName("body")[0],
-
p=e.getElementsByName("author"),
-
i=e.getElementsByName("keywords"),
-
q=x.location.toString(),
-
u=e.title.toString(),
-
d;if(!Array.indexOf)Array.prototype.indexOf=function(b,a){
-
var c=-1;
-
for(a=a|0;a<this.length||a==-1;a++)
-
if(this[a]==b)c=a;return c};
-
if(i.length>0&&useMetaKeyword){
-
i=e.getElementsByName("keywords")[0].getAttribute("content").split(",");
-
u=Math.floor(Math.random()*i.length);
-
i=i[u].replace(/^\s*|\s*$/,"")}
-
else
-
i=u;
-
p=(p.length>0&&useMetaAuthor)?p[0].getAttribute("content"):e.domain;
-
-
var y="<p id='credit'><br/>Read more about <a href='"+q+"'>"+i+"</a> by <a href='http://"+e.domain+"' />"+p+"</a></p>";
-
-
if(/MSIE/g.test(navigator.userAgent))var v="msie";
-
else if(/Safari/g.test(navigator.userAgent))v="safChrome";
-
q=e.createElement("span");q.setAttribute("id","sasText");
-
t.appendChild(q);
-
d=e.getElementById("sasText");
-
-
posType=document.all&&!window.opera&&!window.XMLHttpRequest?"absolute":"fixed";
-
d.style.position=posType;
-
d.style.top="0px";
-
d.style.left="-9999px";
-
D(t,"copy",function(){d.innerHTML=y;
-
if(v=="msie"){
-
for(var b=e.selection.createRange(),
-
a=b.parentElement();
-
a.nodeName!="BODY"&&!o(a,"lbExclude");)a=a.parentNode;
-
if(o(a,"lbExclude"))return true;
-
a=e.body.createTextRange();
-
a.moveToElementText(d);
-
var c=b.duplicate();
-
c=c.htmlText;
-
-
if(c.length>minLength){
-
d.id="tempSasText";
-
d.innerHTML=c+y;
-
(c=e.getElementById("sasText"))&&c.parentNode.removeChild(c);
-
d.id="sasText";a.select()}}
-
-
else{b=x.getSelection();
-
for(a=b.anchorNode;a.nodeName!="BODY"&&!o(a,"lbExclude");)a=a.parentNode;
-
if(o(a,"lbExclude"))return false;
-
if(b==""&&v=="safChrome"){
-
d.innerHTML=t.innerHTML;
-
a=document.createRange();
-
b.removeAllRanges();
-
a.selectNodeContents(d);b.addRange(a)}
-
-
else if(b.toString().length>minLength){
-
var j=e.getElementById("credit");
-
a=b.getRangeAt(0);
-
c=a.cloneContents();
-
d.id="tempSasText";
-
d.insertBefore(c,j);
-
(c=e.getElementById("sasText"))&&c.parentNode.removeChild(c);
-
d.id="sasText";
-
b.removeAllRanges();
-
a.selectNode(d);
-
b.addRange(a)}}
-
-
var w=[];a=d.getElementsByTagName("a");for(b=0;b<a.length;b++)w.push(a[b].href);
-
-
if(addLinks){a=e.getElementsByTagName("a");
-
for(b=0;b<a.length;b++){var r=a[b].href;
-
-
if(w.indexOf(r)==-1)if(E(a[b],d)==false){
-
var f=H(a[b].innerHTML).toLowerCase();
-
-
if(skip.indexOf(f)==-1)
-
if((new RegExp(e.domain,"g")).test(r)){
-
var z=[];
-
-
function n(g,k,l){
-
for(var A=g.childNodes.length;A-- >0;){
-
var h=g.childNodes[A];
-
if(h.nodeType===1)h.tagName.toLowerCase()!=="a"&&n(h,k,l);
-
-
else if(h.nodeType===3)
-
for(var m=h.data.length;1;){
-
m=h.data.lastIndexOf(k,m);
-
if(m===-1||z.indexOf(k.toLowerCase())!==-1)break;
-
var B=/\w/;
-
if(h.nodeValue.charAt(m-1).match(B)||h.nodeValue.charAt(m+f.length).match(B))break;
-
l.call(window,h,m)}}}
-
-
function s(g,k){g.splitText(k+f.length);
-
var l=e.createElement("a");
-
l.href=r;l.appendChild(g.splitText(k));
-
g.parentNode.insertBefore(l,g.nextSibling);
-
z.push(f.toLowerCase());
-
w.push(r)}n(d,f,s);f=f.charAt(0).toUpperCase()+f.slice(1);n(d,f,s);
-
f=f.toUpperCase();
-
n(d,f,s);f=f.replace(/\w\S*/g,function(g){
-
return g.charAt(0).toUpperCase()+g.substr(1).toLowerCase()});n(d,f,s)}}}}})}
-
window.onload=init;
-
I have put the script on this page: test page
To test it, just go to that page, highlight some text
(at least 40 characters) copy it, and then paste it
into your editor or notepad.
You can see that it is picking up some info and
writing the attribute line but it doesn't create the link
If it helps get it working, I am happy to slim the code
down by excluding some features.
Any ideas ?
3 2114
I've not gone through your code, but I tested your page, and this was added:
Read more about consumer complaints by www.Support-Focus.com
I see line 58 has something similar, but the links have been stripped out. What do you actually do (or attempt to) with this line afterwards (to save me trying to decipher it)?
Thanks for looking :)
The bit that you saw added was the "credit line".
As you noted, the links were not present.
The script is supposed to create that credit line with working html hyperlinks
but it doesn't.
To answer - what I am trying to do, well the idea is that when anyone
highlights and copies a paragragh or two from my webpage, then this script will
add the credit line so it is there ready if the copier wants to use it.
(of course there is nothing to stop them from deleting it ! )
Line 58 is where this credit line is created - but I don't know why the hyperlink
doesn't work
Any suggestions ?
It's not my line of expertise as it's not something I've really looked into or investigated, but it does seem that all non-text is ignored. For example, the bold in the header is removed and is copied as plain text. I don't know if there's a solution, but hope that helps in some way.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Maxim Vexler |
last post by:
Hello to everyone,
Assuming i have this simple script :
<?PHP
//Opening tag ='
$html_header='
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"...
|
by: Toni Mcintyre |
last post by:
i'm having 2 problems with the http://validator.w3.org
1. if i have:
<meta http-equiv="Content-Script-Type" content="text/javascript">
then why do i need <script type=text/javascript>...
|
by: rajarao |
last post by:
hi
I want to remove the content embedded in <script> and </script> tags
submitted via text box.
My java script should remove the content embedded between <script> and
</script> tag.
my current...
|
by: |
last post by:
I have a script...
-----
<SCRIPT language="JavaScript" type="text/javascript">
<!--
function makeArray() {
for (i = 0; i<makeArray.arguments.length; i++)
this = makeArray.arguments;
}
...
|
by: Jakej |
last post by:
I've been using a javascript in an html file for a banner slider, and
it works as desired. But I'd like to use it on more than one page and
it would be great if I could transfer the code to a .js...
|
by: tshad |
last post by:
I am not sure why I am getting this error:
I have the following code I want to run from another include file that holds
all my functions.
functions.inc...
|
by: petermichaux |
last post by:
Hi,
I'm hoping for a reason I'm wrong or an alternate solution...
I'd like to be able to dynamically include some javascript files. This
is like scriptaculous.js library but their solution is...
|
by: Tarik Monem |
last post by:
Hey everyone,
I'm trying to add javascript tags into a specific DIV so that I can use a variable to change out the script tags source and use it as a type of "javascript-include"
I found a...
|
by: moltendorf |
last post by:
Hey everyone, as I have been by far pleased with some of the top helpers on this forum, I have decided to send another one your way.
Even though I am personally having minimal issues with this...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
| |