문제

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.

도움이 되었습니까?

해결책

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>

다른 팁

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top