2017-03-31 11 views
0

私は自分のコロナアプリケーション用のコンテンツをHTMLで書いており、native.newWebviewを使ってアプリケーションに表示しています。このHTMLコンテンツ内には、外部Webページへのリンクがあります(例:https://google.com)。Corona Labs - デバイスのブラウザでnewWebViewからリンクを開きます。

ユーザーが自分のアプリでリンクをクリックすると、HTMLコンテンツをアプリに残し、Googleのデバイスのウェブブラウザで開くことができます。

しかし、アプリでリンクをクリックすると、Googleは自分のアプリとウェブブラウザの両方で開くことになります。

iOSでは、初めてリンクをクリックしたときのように見えますが、アプリのデフォルトブラウザでは開きますが、アプリに戻ってリンクを再度クリックすると開きますアプリとブラウザの両方でAndroidの場合、常にアプリとブラウザの両方に表示されます。

ここに私のコードの簡略版があります。

main.lua

local function webListener(event) 
    if event.url then 
     system.openURL(event.url) 
    end 
end 

htmlContent = native.newWebView(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight) 
htmlContent:request("links.html", system.ResourceDirectory) 
htmlContent:addEventListener("urlRequest", webListener) 

そして、ここでは、アプリ内に表示されたリンクを持つHTMLコンテンツです。

links.html

<html> 
<head> 
</head> 
<body> 
    Go to <a href="https://google.com/">Google</a>. 
</body> 
</html> 

答えて

1

てみてください(テスト)

links.html

<html> 
    <head></head> 
    <body> 
    Go to <a href="#corona://https://google.com/>Google</a>. 
    </body> 
</html> 

main.lua

local function webListener(event) 
    if event.url then 
     local pattern = 'corona://' 
     local position = string.find(event.url, pattern) or 0 
     local len = position == 0 and 0 or string.len(pattern) 
     local url = string.sub(event.url, position + len) 
     if len > 0 then -- ensures that the app doesn't try to open links.html in the default browser window 
      system.openURL(url) 
      --print(url) 
     end 
    end 
end 

local htmlContent = native.newWebView(display.contentCenterX, display.contentCenterY, display.contentWidth, display.contentHeight-2*100) 
htmlContent:request("links.html", system.ResourceDirectory) 
htmlContent:addEventListener("urlRequest", webListener) 
関連する問題