SORU
4 Ocak 2011, Salı


Nasıl eğer URL bir dize içeriyorsa kontrol etmek için?

Nasıl böyle bir şey yapabildim:

<script type="text/javascript">
$(document).ready(function () {
    if(window.location.contains("franky")) // This doesn't work, any suggestions?
    {
         alert("your url contains the name franky");
    }
});
</script>

CEVAP
4 Ocak 2011, Salı


Href özellik eklemek ve contains yerine indexOf kontrol etmeniz gerekir

<script type="text/javascript">
$(document).ready(function () {
    if(window.location.href.indexOf("franky") > -1) {
       alert("your url contains the name franky");
    }
});
</script>

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • GALERNAYA20

    GALERNAYA20

    19 NİSAN 2011
  • Miles Fisher

    Miles Fisher

    8 NİSAN 2009
  • RinconDynamic

    RinconDynami

    1 EKİM 2011