Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOMロード完了後の処理 #4

Open
dfkim opened this issue Sep 27, 2018 · 0 comments
Open

DOMロード完了後の処理 #4

dfkim opened this issue Sep 27, 2018 · 0 comments

Comments

@dfkim
Copy link
Owner

dfkim commented Sep 27, 2018

//DOMロード完了後の処理
(function (window, functions) {
	var document = window.document,
	functions = functions && functions.splice ? functions : [],
	ie = document.addEventListener ? false : true,
	complete = false,
	dispose = function () {
		if (complete) {
			return;
		};
		complete = true;
		if (!ie) {
			document.removeEventListener('DOMContentLoaded', onDOMContentLoaded);
			document.removeEventListener('readystatechange', onReadyStateChange);
			window.removeEventListener('load', onWindowLoad);
		}else{
			document.detachEvent('onreadystatechange', onReadyStateChange);
			window.detachEvent('onload', onWindowLoad);
		}
		for(var i = 0, limit = functions.length; i < limit; i++) {
			setTimeout(functions[i], 100 * i);
		}
	},
	onDOMContentLoaded = function (e) {
		dispose();
	},
	onReadyStateChange = function (e) {
		if (document.readyState == 'complete') {
			dispose();
		}
	},
	onWindowLoad = function (e) {
		dispose();
	};
 
	if (!ie) {
		document.addEventListener('DOMContentLoaded', onDOMContentLoaded, false);
		document.addEventListener('readystatechange', onReadyStateChange, false);
		window.addEventListener('load', onWindowLoad, false);
	} else if (document.attachEvent) {
		document.attachEvent('onreadystatechange', onReadyStateChange);
		window.attachEvent('onload', onWindowLoad);
	}
}(window,
	[function () {
	
		//UAをhiddenに格納
		var element = document.createElement('input'); 
		element.id = "userAgent"; 
		element.name = "userAgent"; 
		element.type = "hidden"; 
		element.value = window.navigator.userAgent.toLowerCase(); //UA

		var s = document.getElementsByTagName('script')[0];
		s.parentNode.insertBefore(element, s);
	
	}]
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant