PhoneGap (특히 PhoneGap Build) 및 InAppBrowser를 사용하여 반응이 빠른 온라인 웹 사이트를 사용하기 쉬운 시스템으로 포장하는 앱을 만들고 있습니다.PhoneGap/Cordova에서 InAppBrowser로 기본 브라우저에서 링크 열기
앱은 시스템의 기본 브라우저에서 외부 링크를 여는 기능 하나를 제외하고 잘로드되고 작동합니다.
이것은 95 % 작동하지만 특정 경우에 링크가 리디렉션되는 문제를 일으 킵니 다 (예 : http://www.facebook.comhttps://www.facebook.com으로 리디렉션 됨 https://m.facebook.com으로 리디렉션 됨).
내 코드에서는 URL이 구성된 도메인과 다름을 감지하고이를 새 시스템 창에서 열고 다른 두 리디렉션을로드하고 앱 내에서로드합니다.
원하는 작업은 시스템의 기본 브라우저에서 링크를 열고 추가 처리 (리디렉션 포함)를 모두 중지하는 것입니다.
웹 페이지의 라이브이기 때문에 HTML 페이지의 링크에서 _system
으로 변경하는 것만으로는 앱의 외부에 있기 때문에 작동하지 않습니다.
모든 조언과 조언을 부탁드립니다.
코드의 가장 중요한 발췌
은 다음과 같습니다 폰갭의 응용 프로그램 내에서:
function isExternal(url) {
var match = url.match(/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/);
if (typeof match[1] === "string" && match[1].length > 0 && match[1].toLowerCase() !== location.protocol) return true;
if (typeof match[2] === "string" && match[2].length > 0 && match[2].replace(new RegExp(":("+{"http:":80,"https:":443}[location.protocol]+")?$"), "") !== location.host) return true;
return false;
}
function goToPage(url, external){
if(external)
//Go to new URL with appended hash flag
window.location=encodeURI(url)+'#appExt';
else{
//Show loading screen
$('#app-overlay').css('display','block');
//Wait for 100ms then change page, so the loading screen gets time to show
setTimeout(function(){window.location=encodeURI(url)},100);
}
}
$('a').on('click',function(e){
e.preventDefault();
if(isExternal($(this).attr('href'))){
//If the URL is an external one, the app.js file will open the url in a new window after setting the appExt hash flag
if(debug) alert('Stopping navigation from injection.js as external link detected');
goToPage($(this).attr('href'), true);
}
else{
//Otherwise, continue normally
if(debug) alert('Regular link clicked');
goToPage($(this).attr('href'), false);
}
//Cancel the default link operation, as we've already handled it
return false;
});
: 자바 스크립트 파일에서
//Called on deviceready
function launchSite(){
// Get Webpage in InAppBrowser (using the _blank target) and hide it until loaded
iabRef = window.open(url+'?inApp=true'), '_blank', 'location=no,hidden=yes');
//Attach listener for external link intercepting
iabRef.addEventListener('loadstart', iabLoad);
//Attach listener for loading complete
iabRef.addEventListener('loadstop', iabLoaded);
}
//Check if links are external, if they are, open them in the system's default browser
function iabLoad(event){
if(debug) alert('Page load request for ' + event.url);
//Check the link to see if it is external, which is flagged by #appExt from injection.js
if(event.url.indexOf('appExt') > -1){
//Open the window using the _system target to use the system's default browser
if(debug) alert('Opening '+event.url + ' in system window')
window.open(event.url,'_system');
if(debug) alert('Stopping anything more');
//Mobile redirects keep triggering load events from initial link, stop the process now.
window.stop(); // <-Does not stop
}
else{
if(debug) alert('Opening normally without interference');
}
}
//If window was hidden whilst loading, show it now that it has loaded
function iabLoaded(event){
if(debug) alert('Showing IAB window');
iabRef.show();
}
는 반응 웹 사이트에 포함
업데이트 : 계속 조정 및 재 컴파일이 더 이상 나를 필요로하지 않습니다. 누구든지 나를 위해이 일을 주시 할 수 있습니까?
동일한 문제가 발생했습니다. 해결책을 찾았습니까? – Purva