javascript - Append string to every url on page load -


i have website in english want show in spanish when page loads. so, got script google translate put in header file need append #googtrans(en|fr) @ end of every url. i've done far is:

$(document).ready(function () {   $('a').each(function () {     this.href += '#googtrans(en|es)';   }) }); 

but problem code is, blocking popups , bootstrap dropdowns. there simple way put trailing string every url on page load.

filter out links have attributes or classes don't want hash applied to:

for example:

$('a').not('[data-toggle], [href^="#"]').prop('hash','#googtrans(en|es)');  

if selectors in not() aren't enough can use more robust filter() method

a more ideal approach being able have classes on <a> represent ones want modified.

<a class="translate"> $('a.translate').prop('hash','#googtrans(en|es)');  

or

<div class="translate">    <a> </div> $('.translate a').prop('hash','#googtrans(en|es)');  

note using hash property achieves same concatenating href

without seeing more of html hard provide lot more help


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -