uvula6921 of CREMA Publishing Team
8/9/2018 - 5:58 AM

반응형 스킨에 적용할 공통 스크립트(init.js)와 조건문

설명

  • 이 스크립트들은 하나의 스킨으로 PC와 모바일 사이트를 운영하는 반응형 쇼핑몰에 사용합니다.
<!-- CREMA / Device Detection / cre.ma -->
<script src="//cdn.jsdelivr.net/npm/mobile-detect@1.4.5/mobile-detect.min.js"></script>

<!-- CREMA / 공통 스크립트 (init.js) / cre.ma -->
<script>
  var md = new MobileDetect(window.navigator.userAgent);
  if (md.mobile()) {
    (function(i,s,o,g,r,a,m){if(s.getElementById(g)){return};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.id=g;a.async=1;a.src=r;m.parentNode.insertBefore(a,m)})(window,document,'script','crema-jssdk','//widgets.cre.ma/sampleshop.com/mobile/init.js');
  } else {
    (function(i,s,o,g,r,a,m){if(s.getElementById(g)){return};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.id=g;a.async=1;a.src=r;m.parentNode.insertBefore(a,m)})(window,document,'script','crema-jssdk','//widgets.cre.ma/sampleshop.com/init.js');
  }
</script>
<!-- cre.ma / 게시판형 위젯 / 스크립트를 수정할 경우 연락주세요 (support@cre.ma) -->
<script>
    var md = new MobileDetect(window.navigator.userAgent);
    if (md.mobile()) {
    } else {
      document.write("<div class='crema-product-reviews' data-product-code='{$product_no}' data-widget-id='20' style='width: 800px; margin: 0 auto;'></div>");
    }
</script>
<!-- cre.ma / Device Detection / 스크립트를 수정할 경우 연락주세요 (support@cre.ma) -->
<script src="//cdn.jsdelivr.net/npm/mobile-detect@1.4.5/mobile-detect.min.js"></script>

<!-- cre.ma / 리뷰 게시판 / 스크립트를 수정할 경우 연락주세요 (support@cre.ma) -->
<script>
    (function(c,board_no){
        c=new RegExp("[\\?&]board_no=([^&#]*)").exec(location.search),board_no=c?decodeURIComponent(c[1].replace(/\+/g, " ")):'';
        if (board_no == "4") {
            document.write("<div class='crema-reviews'></div>");
            var md = new MobileDetect(window.navigator.userAgent);
            if (md.mobile()) {
                document.write("<style>.crema-reviews > iframe { max-width: 100% !important; }</style>");
                (function(i,s,o,g,r,a,m){if(s.getElementById(g)){return};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.id=g;a.async=1;a.src=r;m.parentNode.insertBefore(a,m)})(window,document,'script','crema-jssdk','//widgets.cre.ma/sampleshop.com/mobile/init.js');
            } else {
                (function(i,s,o,g,r,a,m){if(s.getElementById(g)){return};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.id=g;a.async=1;a.src=r;m.parentNode.insertBefore(a,m)})(window,document,'script','crema-jssdk','//widgets.cre.ma/sampleshop.com/init.js');
            }
        }
        c=location.href.match(/board[\/][^\/]*[\/](\d+)[\/]*/),board_no=c?decodeURIComponent(c[1].replace(/\+/g, " ")):'';
        if (board_no == "4") {
            document.write("<div class='crema-reviews'></div>");
            var md = new MobileDetect(window.navigator.userAgent);
            if (md.mobile()) {
                document.write("<style>.crema-reviews > iframe { max-width: 100% !important; }</style>");
                (function(i,s,o,g,r,a,m){if(s.getElementById(g)){return};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.id=g;a.async=1;a.src=r;m.parentNode.insertBefore(a,m)})(window,document,'script','crema-jssdk','//widgets.cre.ma/sampleshop.com/mobile/init.js');
            } else {
                (function(i,s,o,g,r,a,m){if(s.getElementById(g)){return};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.id=g;a.async=1;a.src=r;m.parentNode.insertBefore(a,m)})(window,document,'script','crema-jssdk','//widgets.cre.ma/sampleshop.com/init.js');
            }
        }
    })();
</script>
<!-- cre.ma / Device Detection / 스크립트를 수정할 경우 연락주세요 (support@cre.ma) -->
<script src="//cdn.jsdelivr.net/npm/mobile-detect@1.4.5/mobile-detect.min.js"></script>

<!-- cre.ma / 리뷰 게시판 / 스크립트를 수정할 경우 연락주세요 (support@cre.ma) -->
<script>
	(function(c,bdId){
		c=new RegExp("[\\?&]bdId=([^&#]*)").exec(location.search),bdId=c?decodeURIComponent(c[1].replace(/\+/g, " ")):'';
		if(bdId == "goodsreview"){
			document.write("<div class='crema-reviews'></div>");
			var md = new MobileDetect(window.navigator.userAgent);
			if (md.mobile()) {
				document.write("<style>.crema-reviews > iframe { max-width: 100% !important; }</style>");
				(function(i,s,o,g,r,a,m){if(s.getElementById(g)){return};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.id=g;a.async=1;a.src=r;m.parentNode.insertBefore(a,m)})(window,document,'script','crema-jssdk','//widgets.cre.ma/sampleshop.com/mobile/init.js');
			} else {
				(function(i,s,o,g,r,a,m){if(s.getElementById(g)){return};a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.id=g;a.async=1;a.src=r;m.parentNode.insertBefore(a,m)})(window,document,'script','crema-jssdk','//widgets.cre.ma/sampleshop.com/init.js');
			}
		}
	})();
</script>