跳到主要內容

發表文章

目前顯示的是 2014的文章

設定 Cookie 時使用 HttpOnly 特性減低網站安全風險(XSS)

http://blog.miniasp.com/post/2009/11/26/Using-HttpOnly-flag-to-avoid-XSS-attack.aspx asp寫法 Response.AddHeader "Set-Cookie", "CookieName=CookieValue; path=/; HttpOnly" 也可以加上domain, expires,譬如 Response.AddHeader "Set-Cookie", "test=123; domain=localhost; expires="&GetGMT(now()+1)&"; path=/; HttpOnly" function GetGMT(od)   'GMT格式: Tue, 23 Dec 2014 23:19:08 GMT   od=dateAdd("h",8,od)   aWeek=Array("","Sun","Mon","Tue","Wed","Thu","Fri","Sat")   aMonth=Array("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")   nd=aWeek(weekday(od)) &", "& day(od) &" "& aMonth(month(od)) &" "& year(od) &" "& right("00...

jQuery Mobile

1.架構 <html> <head> <title>TITLE</title> <link href="jquery.mobile-1.4.2.min.css" rel="stylesheet"></link> <script src="jquery-1.8.2.min.js"></script> <script src="jquery.mobile-1.4.2.min.js"></script> <script src="https://maps.google.com/maps/api/js?v=3&amp;sensor=false"></script> </head> <body> <div data-role="page"> <div class="header" data-role="header" data-id="persistent" data-position="fixed"> </div> </div> </body> </html> a.<div data-role="page"></div> 每頁都必須有此tag,每頁不同的內容放在此tag內,此tag上方的內容只要首頁有即可,亦即jQuery Mobile在讀取首頁外的頁面時只會擷取那頁的<div data-role="page"></div> 內的內容,因此,若有js或css是某頁才需要用到的話,就要寫在 <div data-role="page"></div>裡面,而不是寫在<head></head>裡。 b. <div class="h...

jQuery: placeholder fixed for IE 8

$(document).ready(function () { $('[placeholder]').focus(function () { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); input.removeClass('placeholder'); } }).blur(function () { var input = $(this); if (input.val() == '' || input.val() == input.attr('placeholder')) { input.addClass('placeholder'); input.val(input.attr('placeholder')); } }).blur(); $('[placeholder]').parents('form').submit(function () { $(this).find('[placeholder]').each(function () { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); } }) }); }); CSS Styling ::-webkit-input-placeholder { color: red; } :-moz-placeholder { color: red; } .placeholder { color: #ccc; }

jQuery: Radio Button, Checkbox and Selecter

Trigger the event: $("input[name='lom']").change(function(){ // Do something interesting here }); Radio Button: To get the selected value: var v=$('input[name=Sex]:checked').val(); if( typeof(v) == 'undefined'){ //there's no button selected } To select radio button from value: $("input[name=Sex][value='2']").attr('checked',true); To select radio button from index: $('input[name=Sex]')[1].checked = true; Checkbox: To see whether checkbox is checked: $('#chk').is(':checked'); To set checkbox: $("#chk1").attr("checked",''); $("#chk2").attr("checked",true); Selecter: To get the selected value: $('#selectList').val(); $('#selectList :selected').text(); To add a new option: $('#selectList').addOption(value,text);

Ajax pageview of Google Analytics

first, to be sure the google analytics api is new version, such as var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-xxxxxx-x']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); the way 1. use ajaxSetup for all calls to $.ajax. notice 1: ajaxSetup is better writeen within $( document ).ready() to be sure the google analytics api is loaded. notice 2: the opts.url is the ajax url you write, to record corect pageview, the best way is use fullpath, such as '/folder_name/filename.php' $(function () { $.ajaxSetup({ beforeSend: function (xhr, opts) { //avoid cache of the iOS6 Safa...