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

  • Jay Will

    Jay Will

    19 NİSAN 2006
  • Moodle

    Moodle

    11 Mayıs 2010
  • SoundHound

    SoundHound

    8 Mart 2006