팝업 프린트 후 창 자동 닫기

Open API/그 외 |2018. 9. 14. 11:05
반응형

modal 팝업 , 일반 팝업 , 레이어 팝업 등등..온갖 팝업이 난무하는데


프린트하기가 너무 힘든 상황 통합으로 사용하기 위해서 방법을 찾아봤습니다.


어떤 경우 어떤 브라우저 버전에서는 


window.print() 후 window.close() 하면 


프린트 창이 뜨기도 전에 창이 닫히는 상황이 발생하기도하고..


포인트는 출력 후 onfocus 되었을때 창을 닫는다는 것.


최종 적으로는 아래 글에서 내용을 찾아서 처리했습니다.


여러 상황에 히스토리를 갖고 수정방법이 나열되어있습니다.


https://code-examples.net/en/q/6294d6


var content = "Hello";


newWin= window.open();

newWin.document.open();

newWin.document.write(content);

newWin.document.close();

setTimeout(function(){

	newWin.print();

	newWin.onfocus=function(){ newWin.close();}

},500);




댓글()

ip 주소로 국가 조회하는 방법 about.ip2c.org API

Open API/그 외 |2018. 8. 30. 17:08
반응형

아이피주소로 국가 조회하기


서비스하는 내용이 국가별로 제한되는 부분이라


DB를 구축하자니 그 업데이트관리가 문제이고


API가 있지 않을까 해서 구글링을 통해 알게된 사이트입니다.



https://about.ip2c.org



Request : 


https://ip2c.org/8.8.8.8


Response : 


1;US;USA;United States


; 로 구분자가 지정되어있으며


0 : WRONG INPUT , 1 : NORMAL , 2 : UNKNOWN 


US : ISO 국가코드 








아래 내용은 about.ip2c.org 사이트에서 발췌한 INPUT/OUTPUT 설명입니다.

 
==== Accepted inputs: ============================================================

You can use http or https.

https://ip2c.org/XXX.XXX.XXX.XXX
or
https://ip2c.org/?ip=XXX.XXX.XXX.XXX
|
+ standard IPv4 from 0.0.0.0 to 255.255.255.255
+ e.g. we take your IP:
    |
    + URL looks like this:  https://ip2c.org/128.134.3.161
    |                       or
    |                       https://ip2c.org/?ip=128.134.3.161
    |
    + resulting string is:  1;KR;KOR;Korea Republic of


https://ip2c.org/XXXXXXXXXX
or
https://ip2c.org/?dec=XXXXXXXXXX
|
+ decimal number from 0 to 4294967295 (MAX_INT)
+ faster than ?ip= option, less server-side processing
+ to convert IPv4 to decimal you only need to know this:
    |
    + (IPv4) A.B.C.D == A*256^3 + B*256^2 + C*256 + D (decimal)
    + e.g.   5.6.7.8 == 5*256^3 + 6*256^2 + 7*256 + 8
                     == 5*16777216 + 6*65536 + 7*256 + 8
                     == 83886080 + 393216 + 1792 + 8
                     == 84281096


https://ip2c.org/s
or
https://ip2c.org/self
or
https://ip2c.org/?self
|
+ processes caller's IP
+ faster than ?dec= option but limited to one purpose - give info about yourself


Caution
Some clients (e.g. ASP) may have issues while trying to open a file over HTTP.
In that case a slash / preceding ?ip= is obligatory.
==== Possible outputs: ===========================================================

You can use http or https.

0;;;WRONG INPUT
|
+ your request has not been processed due to invalid syntax
    |
    + e.g. bad IPv4 like 300.400.abc.256
    + e.g. bad decimal like 2a3b4c or bigger than MAX_INT


1;CD;COD;COUNTRY
|
+ contains two-letter (ISO 3166) and three-letter country codes, and a full country name
+ country name may be multi-word and contain spaces
+ e.g. we take your IP:
    |
    + URL looks like this:  https://ip2c.org/128.134.3.161
    |                       or
    |                       https://ip2c.org/?ip=128.134.3.161
    |
    + resulting string is:  1;KR;KOR;Korea Republic of


2;;;UNKNOWN
|
+ given ip/dec not found in database or not yet physically assigned to any country


The first digit indicates status so you don't have to always parse the whole string.
Output is always semicolon delimited text/plain - you can pass it to any type of application.


댓글()

Javascript , Data URL을 이용한 엑셀 파일 생성하기

Open API/그 외 |2018. 2. 21. 17:12
반응형





javascript 에서 테이블 구조의 html을 전달 받아 Excel 파일을 생성하는 함수 입니다.


기본적으로 서버에서 만들어진 내용을 다운받도록 하지만 

클라이언트 쪽에서 바로 xls 파일을 생성 할 수 있도록 하는 방법입니다.

기본문법 : data:[<mediatype>][;base64],<data>



    
function fnExcelReport(cont, fileName)
{
	var ua = window.navigator.userAgent;
         
	if ( (navigator.appName == 'Netscape' && ua.search('Trident') != -1) || (ua.indexOf("msie") != -1) )       // IE
	{
		newWin = window.open();
		newWin.document.open("txt/html","replace");
		newWin.document.write(cont);
		newWin.document.close();
		newWin.focus();
		newWin.document.execCommand("SaveAs", true, fileName + ".xls");
		newWin.close();
	}
	else   //other browser
	{
		var a = document.createElement('a');
		var data_type = 'data:application/vnd.ms-excel';
		a.href = data_type + ', ' + encodeURIComponent(cont);
		a.download = fileName+'.xls';
		a.click();
		e.preventDefault();
	}
}


상세 내용은 MDN 웹 Document 를 참조하세요.


링크 : https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs

댓글()