顯示具有 JavaScript 標籤的文章。 顯示所有文章
顯示具有 JavaScript 標籤的文章。 顯示所有文章

2013年2月4日 星期一

Same origin policy

依據 Wikipedia [1] 上對於 Same origin policy 的描述如下:
In computing, the same origin policy is an important security concept for a number of browser-side programming languages, such as JavaScript. The policy permits scripts running on pages originating from the same site – a combination of scheme, hostname, and port number[1] – to access each other's methods and properties with no specific restrictions, but prevents access to most methods and properties across pages on different sites.

2013年1月5日 星期六

在 JavaScript 中複製物件

在 JavaScript 當中,直接用 = 做物件複製的話,好像是會直接複製整個物件的 referrence
如果想要把一個物件複製出另外一個內容相同的物件,就只能用迴圈的方式自行複製
在 StackOverflow [1] 上找到一段還不錯的參考程式碼(原作者是 A. Levy),內容如下:

2012年8月23日 星期四

JavaScript 驗證數字

要驗證某個變數的值是不是數字,在 JavaScript 當中好像用 Regular Expression 結果會怪怪的
我試了好幾種不同的 Regular Expression,但用 match() 時都有些奇怪的問題
經由同事的協助,發現 [1] 當中 Joel Coehoorn 的回應~

2012年5月1日 星期二

Google Map API 入門教學(二):在 Map 上加入標記

要在 Google Map 上加入標記,需要利用的是 google.maps.Marker 這個物件。
延續 Google Map API 入門教學(一)的例子,可以將 JavaScript 加上以下的語法:

google.maps.event.addListener(currentMap, "click", function(event) {
  // Setting of marker
  var optionOfMarker = {
    position: event.latLng,
    map: currentMap,
    title: event.latLng.toString()
  };

  // Show marker in the place of mouse clicks
  mapMarker = new google.maps.Marker(optionOfMarker);
});

2012年4月24日 星期二

Google Map API 入門教學(一):將 Google Map 放入網頁

Google Map API 目前已經是 v3 版本了,不需要特別申請 API,不過規定跟之前一樣,不能將 Google Map API 用在需要付費的地方。

Google 官方文件其實已經有蠻不錯的入門教學,不過說明個人覺得稍微少了點
所以自己在學習的同時也順便來記錄一下!

要在網頁上顯示 Google Map,最基礎需要的就是一個 HTML 網頁
然後網頁中去執行 Google 提供的 JavaScript API 在網頁上顯示地圖。
網頁的部份其實後續很少在改,因為動作幾乎都是靠 JavaScript 在做的。