Pergunta

I have a question about retrofitting the following code to gracefully handle noscript scenario.

Call me <a href="" onclick="activateContact(); return false;" unselectable="on"> <span>My Contact</span> </a>

I'd like to subsitute the line above in case of noscript with:

Call me at 1-800-555-1525. 

Thanks in advace.

Foi útil?

Solução

script tag is used for javaScript. Same way there is tag which gets in action when the Javascript is diabled in browser. So to substitute your anchor with noscript data when JS is disbaled in browser. Use this

<script>
  Call me <a href="" onclick="activateContact(); return false;" unselectable="on"> 
  <span>My Contact</span> </a>
</script>


<noscript>
    Call me at 1-800-555-1525. 
</noscript>

Outras dicas

Set the link to noscript behavior:

 Call me at <a  id="callMeLink" href="#" unselectable="on"> <span>1-800-555-1525.</span> </a>

Then do the progressive enhancement with js. If the js is not activated in browser, the link above will be on the right format already.

<script>
   var callMeLink = document.getElementById("callMeLink");
   callMeLink.onclick = activeContact;
   callMeLink.innerHTML = "<span>My Contact</span>";
</script>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top