Skip to content Skip to sidebar Skip to footer

How To Use Onclcik And Href In Anchor Tag And Make Only Onclick Work.href Is Only For Google Crawling

In my website when i click on images it opens new page using onclcik openpopup(user defined function) my problem is google will not index onclcik urls,it only index href urls. So i

Solution 1:

Fix your code. Place the elements in quotes. Work correctly with quotes.

    var imgurl = "http:"+lcurl+touch_id+".jpg";
    var data = "<divid='charm_"+touch_id+"'data-charmid='"+touch_id+"'data-vis='"+bgid+"'data-vid='"+seid+"'data-vtitle='"+vtitle_url+"'data-title='"+title_url+"'style='float:left;'class='mdl-cell mdl-cell--4-col charm-wrapper'><divclass='mdl-card-wrapper charm-inner'><divclass='demo-card-wide mdl-card mdl-shadow--8dp'><divclass='mdl-card__media'>"+locicon+"<ahref='"+popupurl+"'id='myAnchor' ><divstyle='position:relative;'><divstyle='position:absolute;z-index:9;right:0px;bottom:0px;'><imgwidth='32px'src='"+cf_assets+"img/hanger.png'></div><divid='imagearea_"+touch_id+"'title='"+title+"'class='imagearea loading'></div></div></a></div><divclass='mdl-card__title'><divclass='right-charm'><divclass='social-share'>"+copycontent+""+watsapp+"<aonclick='sharetofb(\'"+ct_domain+socialshare_url+"\');' title='Facebook'id='fb"+touch_id+"'class='fb_share'></a><aonclick='sharetotwitter(\'"+ct_domain+socialshare_url+"\');' title='Twitter'id='tw"+touch_id+"'class='tw_share'></a></div></div><divclass='icharm'><h2class='mdl-card__title-text'>"+subtitle+"</h2><divclass='mdl-card__subtitle-text'>"+title+"</div><divid='vid_"+touch_id+"'class='mdl-card__subtitle-videoname'>"+videoname+"</div></div></div></div></div></div>";

    $('#main-home-page-inner').add(HTML(data));
    callcloudinary(imgurl,title,touch_id);
    callmasonry();

    if(i == setarr.length-1)
    {
        localStorage.touchids=touchid_arr.join(",");
        localStorage.searchresults=gcharmarr.join(",");
    }
    }
} // WHY????

$('myAnchor').on('click',function(ev){ 
ev.preventDefault();
openpopup(ev.target.getAttribute("popupurl"));
sendpym(ev.target.getAttribute("data-charmid"));

See how to properly use the quotes ' and "in a variable in w3schools.com - JavaScript Strings

Solution 2:

You can easily do this by returning false from the handler function at the end.

Refer to this post for more details

Also, you can use something like this if you are using JQuery:

$('a').on('click',function(e){ 
     e.preventDefault();
     // Do your other stuff.
});

In this example I am targeting your anchor tag by tagname. Add a class or ID instead.

Post a Comment for "How To Use Onclcik And Href In Anchor Tag And Make Only Onclick Work.href Is Only For Google Crawling"