Skip to content

Instantly share code, notes, and snippets.

window.command = '';
function sendCommand(s) {
window.command = s;
location.href = 'crab://test';
}
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURL * url = [request URL];
if ([[url scheme] isEqualToString:@"crab"]) {
// 在这里做js调native的事情
// ....
// 做完之后用如下方法调回js
[webView stringByEvaluatingJavaScriptFromString:@"window.command"];
return NO;
function createListView(id) {
var listView = $('<div>').addClass('list').click(function(e) {
var $this = $(this),
$target = $(e.target);
if ($(e).is('li')) {
$(e.target).addClass('selected');
}
$.data($this, 'selected', $target.text());
}).keypress(function(e) {
var ListView = Backbone.View.extend({
tagName: 'div',
className: 'list',
events: {
'click li': 'clickItem',
'keypress': 'deleteOnKeypress'
},
clickItem: function(e) {
var $target = $(e.target);
// 没有依赖Backbone的History机制,而是调用Native命令实现页面切换,
// 由Native来统一管理History。
$(document).on('click', 'a, .url', function(e) {
e.preventDefault();
var pattern = /#!(.+)/,
$this = $(this),
href = $this.attr('href') || $.this.data('url');
if (href && href.match(pattern)) {
.center {
top: 25%;
text-align: center;
}
<h1>居中的标题</h1>
h1 {
.center;
}
function getPerfStats() {
var timing = window.performance.timing;
return {
dns: timing.domainLookupEnd - timing.domainLookupStart,
connect: timing.connectEnd - timing.connectStart,
ttfb: timing.responseStart - timing.connectEnd,
basePage: timing.responseEnd - timing.responseStart,
frontEnd: timing.loadEventStart - timing.responseEnd
};
}
export CA_COLOR_OPAQUE=1
export CA_LOG_MEMORY_USAGE=1
/Applications/Safari.app/Contents/MacOS/Safari
/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator
_.utils.api('baidu.ting.song.play', {
songid: sid
}, {
expires: 0
}).done(function(r) {
self._curSong = r;
self.setUrl(r.bitrate.file_link);
self.trigger('player:fetch', r);
}).fail(function(r) {
// TODO: server返回错误,之后要记录日志或重试
Backbone.Router.extend(_.extend(redirectRouter, {
routes: {
'': 'index',
'search/:query/p:page': 'search', // #search/kiwi/p7
'song/:id/': 'song' // #song/87336123/
// ...
},
search: function(query, page) {