cordova-pulgin-whitelist 사용법

|


코도바로 프로잭트를 생성하면 기본적으로 설치되는 플러그인입니다.(5.x 버전 확인)

4.0대부터는 http 로 시작하는 주소를 직접입력하거나 location.replace 등으로 주소를 직접 입력하는경우 새창으로 페이지가 열리도록 되어있습니다.

경우에 따라서는 새창에서 열리지않고 웹뷰가 리프레쉬되도록 하고싶을때가 있습니다.

코도바에서 새창에서 페이지가열리지않도록 하려면 whitelist 플러그인을 세팅해주어야합니다.

(참고 : https://github.com/apache/cordova-plugin-whitelist)


아래처럼 config.xml에 allow-navigation 태그를 이용해서 웹뷰에서 해당 페이지가 열리도록 설정할수있습니다.

location.href,replace 뿐만아니라 <a href="..."> 도 마찬가지입니다.


<!-- Allow links to example.com -->
<allow-navigation href="http://example.com/*" />

<!-- Wildcards are allowed for the protocol, as a prefix
     to the host, or as a suffix to the path -->
<allow-navigation href="*://*.example.com/*" />

<!-- A wildcard can be used to whitelist the entire network,
     over HTTP and HTTPS.
     *NOT RECOMMENDED* -->
<allow-navigation href="*" />

<!-- The above is equivalent to these three declarations -->
<allow-navigation href="http://*/*" />
<allow-navigation href="https://*/*" />
<allow-navigation href="data:*" />

반대로 allow-intent 하면 새로운창에서 href=주소에 대한 페이지가 열리게됩니다.


<!-- Allow links to web pages to open in a browser -->
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />

<!-- Allow links to example.com to open in a browser -->
<allow-intent href="http://example.com/*" />

<!-- Wildcards are allowed for the protocol, as a prefix
     to the host, or as a suffix to the path -->
<allow-intent href="*://*.example.com/*" />

<!-- Allow SMS links to open messaging app -->
<allow-intent href="sms:*" />

<!-- Allow tel: links to open the dialer -->
<allow-intent href="tel:*" />

<!-- Allow geo: links to open maps -->
<allow-intent href="geo:*" />

<!-- Allow all unrecognized URLs to open installed apps
     *NOT RECOMMENDED* -->
<allow-intent href="*" />

access  태그 ajax 요청에 대한 허용여부를 설정을 할수있습니다.


<!-- Allow images, xhrs, etc. to google.com -->
<access origin="http://google.com" />
<access origin="https://google.com" />

<!-- Access to the subdomain maps.google.com -->
<access origin="http://maps.google.com" />

<!-- Access to all the subdomains on google.com -->
<access origin="http://*.google.com" />

<!-- Enable requests to content: URLs -->
<access origin="content:///*" />

<!-- Don't block any requests -->
<access origin="*" />


어떠한 access에대한 정의도 없다면 file:// 만 요청이 허용가능해집니다.






And