Results 1 to 3 of 3

Thread: Adwords Implementation

  1. #1
    Join Date
    May 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Adwords Implementation

    Hi my new project requires something like google adwords.

    So for example, an user searches for something in our intranet. When the user opens the page, the page is loaded. All the keywords matching my dictionary will be underlined, and when the user does a mouseover, it will refer to a definition in my dictionary.

    So my main question is this:

    If I have a definition of the keywords, how do I create a script that will parse through all the HTML Output of other web pages?

    The only way I can think of is a hidden iframe...

    Any suggestions would be greatly appreciated!

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <style type="text/css">
    /*<![CDATA[*/
    .pop1 {
      position:absolute;z-Index:101;visibility:hidden;width:100px;background-Color:#FFFFCC;
    }
    
    .pop2 {
      position:absolute;z-Index:101;visibility:hidden;width:100px;background-Color:#FFCC66;
    }
    /*]]>*/
    </style><script type="text/javascript">
    /*<![CDATA[*/
    
    var MyAry=[];
    MyAry[0]=['some','This is some']
    MyAry[1]=['words','This is words','pop2']
    
    function zxcPop(){
     this.ary=[];
     this.words(document.body);
     this.pops=[]
     for (var z0=0;z0<this.ary.length;z0++){
      for (var z0a=0;z0a<MyAry.length;z0a++){
       if (this.ary[z0].firstChild.data.replace(/[\s&#'"\/;:?,.<>\\*%$£€@()]/img,'').toLowerCase()==MyAry[z0a][0]){
        this.ary[z0].style.textDecoration='underline';
        if (MyAry[z0a][1]){
         this.pops[z0a]=[this.ary[z0],zxcES('DIV',{},document.body)];
         this.pops[z0a][1].innerHTML=MyAry[z0a][1];
         this.pops[z0a][1].className=MyAry[z0a][2]||'pop1';
         this.addevt(this.ary[z0],'mouseover','popup',z0a);
         this.addevt(this.ary[z0],'mouseout','popup',z0a);
        }
       }
      }
     }
    }
    
    zxcPop.prototype.popup=function(e,nu){
     zxcES(this.pops[nu][1],{visibility:(e.type=='mouseover'?'visible':'hidden'),left:zxcPos(this.pops[nu][0])[0]+'px',top:zxcPos(this.pops[nu][0])[1]-this.pops[nu][1].offsetHeight+'px'});
    }
    
    zxcPop.prototype.words=function(n){
     var nu=n.childNodes.length,z0,z1,txt,rn,s,nn;
     for(z0=0;z0<nu;z0++) {
      txt=n.firstChild.data;
      rn=n.removeChild(n.firstChild);
      if(rn.nodeType==3){
       s=txt.split(' ');
       for(var nn,z1=0;z1<s.length;z1++) {
        nn=document.createElement('A');
        nn.className='zxc';
        nn.appendChild(document.createTextNode(s[z1]+' '));
        n.appendChild(nn);
        this.ary.push(nn);
       }
      }
      else {
       zxcWords(rn);
       n.appendChild(rn);
      }
     }
    }
    
    
    zxcPop.prototype.addevt=function(o,t,f,p){
     var oop=this;
     if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](e,p);}, false);
     else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](e,p); });
     else {
      var prev=o['on'+t];
      if (prev) o['on'+t]=function(e){ prev(e); oop[f](e,p); };
      else o['on'+t]=o[f];
     }
    }
    
    function zxcPos(obj){
     var rtn=[0,0];
     while(obj){
      rtn[0]+=obj.offsetLeft;
      rtn[1]+=obj.offsetTop;
      obj=obj.offsetParent;
     }
     return rtn;
    }
    
    
    function zxcES(ele,style,par,txt){
     if (typeof(ele)=='string') ele=document.createElement(ele);
     for (key in style) ele.style[key]=style[key];
     if (par) par.appendChild(ele);
     if (txt) ele.appendChild(document.createTextNode(txt));
     return ele;
    }
    
    
    
    /*]]>*/
    </script>
    
    </head>
    
    <body onload="W=new zxcPop();">
    Some more Words.
    
    </body>
    
    </html>

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    MEGASILVER (07-04-2009)

  4. #3
    Join Date
    May 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    This is brilliant! But I cannot really call the javascript during onload as it is not my page.

    Looks like I have to use iframe to control the body!

    Thanks man! I will start working on it!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •