Adem Kıvanç

PHP - Js Developer

Menü Kapat

Kategori: Native Javascript

VerbalExpressions ile regular expressions artık çocuk oyuncağı

Basit ve okunaklı regex kontrolleri yazmak için geliştirilmiş güzel bir kütüphane VerbalExpressions.

Kütüphane her dil için yazılmış.

Js için olan örnek aşağıdaki gibi.

// Create an example of how to test for correctly formed URLs
var tester = VerEx()
    .startOfLine()
    .then('http')
    .maybe('s')
    .then('://')
    .maybe('www.')
    .anythingBut(' ')
    .endOfLine();

// Create an example URL
var testMe = 'https://www.google.com';

// Use RegExp object's native test() function
if (tester.test(testMe)) {
    alert('We have a correct URL'); // This output will fire
} else {
    alert('The URL is incorrect');
}

console.log(tester); // Outputs the actual expression used: /^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/

“Resmi farklı kaydet” eylemini yakalama. ( Javascript “Save Image As” detect )

Resmi farklı kaydet eventini normal koşullarda yakalayamıyoruz. Fakat blur eventini kullanarak, bu soruna basit bir  çözüm bulmuş oluyoruz.

saveImageAs

javascript ile konum bulma

The Geolocation API’yi neredeyse bütün tarayıcılar destekliyor.

Destekleyen tarayıcıların listesi.

function getLocation () {
  // Tarayıcınızın  Geolocation API desteği var mı?
  if (!navigator.geolocation) {
    alert('Tarayıcınız Geolocation desteği bulunmuyor')
  } else {
    navigator.geolocation.getCurrentPosition(function (position) {
      // Mevcut konumumuzun kordinatlarını alıyoruz.
      var lat = position.coords.latitude
      var lng = position.coords.longitude
       alert("latitude:"+ lat + " longitude:" +lng)

    })
  }
}

Demo yapalım.

© 2024 Adem Kıvanç. Tüm hakları saklıdır.

Tema yapımcısı Anders Norén.