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
Post a Comment