跳至主要内容

博文

目前显示的是 十一月, 2012的博文

javascript stop buffering when tab is inactive.

var $div = $ ( 'div' ); var a = 0 ; setInterval ( function () { a ++; $div . stop ( true , true ). css ( "left" , a ); }, 1000 / 30 ); Inactive browser tabs buffer some of the  setInterval  or  setTimeout  functions. stop(true,true)  will stop all buffered events and execute immediatly only the last animation. The  window.setTimeout()  method now clamps to send no more than one timeout per second in inactive tabs. In addition, it now clamps nested timeouts to the smallest value allowed by the HTML5 specification: 4 ms (instead of the 10 ms it used to clamp to) from:  http://stackoverflow.com/questions/5927284/how-can-i-make-setinterval-also-work-when-a-tab-is-inactive-in-chrome?answertab=active#tab-top

wait something loaded befero execute a acript.

waitForJ = function(fn, attemptsLeft) { var tick = attemptsLeft || 30; if (typeof(updatePhoneNew) == 'undefined' ) { //_gaq isn't registered yet if (tick > 1) { //recurse setTimeout(function() { waitForJ(fn, tick - 1); }, 100); } else { //no ticks left, log error console.log('failed to load window.gaq'); } } else { //gaq is loaded, fire fn fn(); } }; waitForJ(function() { //here's all my code... $J( '#phone_link' ).trigger('click'); }); this script can be used on vivastreet to show the phone number automatically by chrome extension.

add a custom loger filer

services: my_logger: class: Monolog\Logger arguments: [my_info] calls: - [pushHandler, [@my_log_handler]] my_log_handler: class: Monolog\Handler\StreamHandler arguments: [%kernel.root_dir%/logs/my_info.log, 100] Usage (in  Controller , for example): $this->get('my_logger')->info('info message');

remove html tag in string.

An obvious simple solution is to run strip_tags() over it, but that would simply remove tags and leave all text content intact, including embedded javascript and CSS, as well as all text inside elements that are normally hidden (e.g. by setting display: none on them). You could try some regex magic to filter out the parts you're not interested in, but regular expressions on HTML are generally a bad idea for anything nontrivial. The ultimate solution is, I'm afraid, to use a proper HTML parser and then pull the actual text out of the resulting DOM tree - by the time you have that, you'll be pretty close to implementing a web browser. form: http://stackoverflow.com/questions/5572469/get-html-output-cleaned-text-with-php

jquery get tag type

Getting the element type the jQuery way: var elementType = $(this).prev().prop('tagName'); Checking for specific element type: var is_element_input = $(this).is("input"); //true or false then you can do this: if ($('#myiframe').is('iframe')) $("#myiframe").contents().find("#myContent")

php array function

a good explaination for array_merge, +. array_push http://www.java-samples.com/showtutorial.php?tutorialid=997 You want to combine two arrays into one. Use  array_merge( ) : $garden = array_merge($fruits, $vegetables); The  array_merge( )  function works with both predefined arrays and arrays defined in place using array( ) : $p_languages = array('Perl', 'PHP'); $p_languages = array_merge($p_languages, array('Python')); print_r($p_languages); Array ( [0] => PHP [1] => Perl [2] => Python ) Accordingly, merged arrays can be either preexisting arrays, as with  $p_languages , or anonymous arrays, as with  array('Python') . You can't use  array_push() , because PHP won't automatically flatten out the array into series of independent variables, and you'll end up with a nested array. Thus: array_push($p_languages, array('Python')); print_r($p_languages); Array ( [0] => PHP [1] => Pe

include css in ie8

According to  this  bug report on the jquery site, there may well be a problem in IE8 with appending css files to the dom that contain relative links. The poster of the bug suggests that adding it as follows may work: var style = document . createElement ( "link" ); style . setAttribute ( "type" , "text/css" ); style . setAttribute ( "rel" , "stylesheet" ); style . setAttribute ( "href" , "xxx.css" ); jQuery ( "head" )[ 0 ]. appendChild ( style ); Or that using an absolute url may also work: $ ( ' ' ). appendTo ( 'head' ); ​ Although he goes on to say that any files included through @import within the appended css file will also not load as expected. I would suggest giving these test cases a whirl to see what loads for you and what doesn't (if it works you should get a grey background in the HTML window): Method Used in OP's question: 

change apache password file:

http://httpd.apache.org/docs/2.2/programs/htpasswd.html htpasswd  htpasswd  [ - c  ] [ - m  ] [ - D  ]  passwdfile   username htpasswd  - b  [ - c  ] [ - m  | - d  | - p  | - s  ] [ - D  ]  passwdfile   username   password htpasswd  - n  [ - m  | - d  | - s  | - p  ]  username htpasswd  - nb  [ - m  | - d  | - s  | - p  ]  username   password htpasswd /usr/local/etc/apache/.htpasswd-users jsmith Adds or modifies the password for user  jsmith . The user is prompted for the password. The password will be encrypted using the modified Apache MD5 algorithm. If the file does not exist,  htpasswd  will do nothing except return an error. htpasswd -c /home/doe/public_html/.htpasswd jane Creates a new file and stores a record in it for user  jane . The user is prompted for the password. If the file exists and cannot be read, or cannot be written, it is not altered and  htpasswd  will display a message and return an error status. htpasswd -db /usr/web/.htpasswd-al

DateTime 不能用=来复制

$date1 = new DateTime (); $date2 = new DateTime (); $date2 -> add ( new DateInterval ( 'P3Y' )); This seems pretty damn obvious, so if I'm just not understanding, let me know. Update: If you want to copy rather than reference an existing DT object, use  clone , not  = . $a = clone $b;

chrome extension can not access in page variable.

http://stackoverflow.com/questions/10527625/google-chrome-extension-script-injections "name" : "Chrome Extension" , "version" : "1.0" , "manifest_version" : 2 , "content_scripts" : [{ "matches" : [ "http://pagetoinject/script/into/*" ], "js" : [ "contentscript.js" ] }] contenscript.js var s = document . createElement ( 'script' ); s . src = chrome . extension . getURL ( "script.js" ); ( document . head || document . documentElement ). appendChild ( s ); s . parentNode . removeChild ( s ); also tried  this  method with no success var s = document . createElement ( 'script' ); s . src = chrome . extension . getURL ( "script.js" ); s . onload = function () { this . parentNode . removeChild ( this ); }; ( document . head || document . documentElement ). appendChild ( s ); and I keep getting this error o