Skip to content

Instantly share code, notes, and snippets.

@zmmbreeze
zmmbreeze / redirect.html
Created January 27, 2016 12:00
redirect
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>跳转中...</title>
</head>
<body>
<script>
(function(url) {
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
function fireClickEvent(el) {
var event;
// phantomjs目不支持new Event()的形式:https://github.com/ariya/phantomjs/issues/11289
if (document.createEvent) {
event = document.createEvent('MouseEvent');
event.initEvent('click', true, true);
el.dispatchEvent(event);
}
else if (el.fireEvent) {
hasAttribute = function(node, attribute) {
node = node.getAttributeNode(attribute);
return !!(node && node.specified);
};
@zmmbreeze
zmmbreeze / autoFitIframe.js
Created March 27, 2014 09:28
使同域的iframe宽度撑满其所在容器,并且高度自适应其内容
/**
* 使同域的iframe宽度撑满其所在容器,并且高度自适应其内容
*
* @param {Element} iframe .
*/
function autoFitIframe(iframe) {
var doc = iframe.contentDocument || iframe.contentWindow.document;
// 设置iframe宽度
iframe.style.width = '100%';
@zmmbreeze
zmmbreeze / executeScript.js
Last active August 29, 2015 13:57
执行远程或内敛javascript,支持script中包含document.write。用于将js广告渲染到target, 基于tangram
/**
* 执行远程或内敛javascript,支持script中包含document.write
* 用于将js广告改为渲染到target, 基于tangram
*
* executeScript({
* 'target': baidu.g('ad'),
* 'url': 'http://ecma.bdimg.com/adtest/0116fb68cf061c3ec55516d4c79946ca.js'
* });
*
* executeScript({
@zmmbreeze
zmmbreeze / stringify.js
Created March 7, 2014 09:13
json stringify can deal with circular reference
// http://stackoverflow.com/questions/11616630/json-stringify-avoid-typeerror-converting-circular-structure-to-json/11616993#11616993
var o = {};
o.o = o;
var cache = [];
JSON.stringify(o, function(key, value) {
if (typeof value === 'object' && value !== null) {
if (cache.indexOf(value) !== -1) {
// Circular reference found, discard key
return;
@zmmbreeze
zmmbreeze / getGlobal.js
Created March 5, 2014 08:46
Get global in node and browser
(function(win) {
// Do something with the global
})(Function('return this')());
/*!
* jQuery JavaScript Library v2.1.1pre
* http://jquery.com/
*
* Includes Sizzle.js
* http://sizzlejs.com/
*
* Copyright 2005, 2014 jQuery Foundation, Inc. and other contributors
* Released under the MIT license
* http://jquery.org/license
@zmmbreeze
zmmbreeze / inView.js
Created December 19, 2013 08:15
Is element in client view. use tangram
var inView = function (e) {
var clientW = baidu.page.getViewWith();
var clientH = baidu.page.getViewHeight();
var rect = e.getBoundingClientRect();
return (rect.bottom > 0 && rect.top < clientH)
&& (rect.right > 0 && rect.left < clientW);
};