apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.15k stars 987 forks source link

How to load sub index.html page to localhost in cordova ios #1279

Closed Jung-Hey closed 1 year ago

Jung-Hey commented 1 year ago

I am working on an ios project with cordova wkwebkit. Of course, I know that cordova recommends spa. In the case of the main index.html file, the page was opened on localhost as shown below in config.xml.

<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />

<platform name="ios">
    <preference name="scheme" value="app" />
    <preference name="hostname" value="localhost" />
</platform>

Then you can see that the result of checking in Chrome developer mode is applied successfully.

스크린샷 2022-12-27 오후 1 02 48

But in the case of the sub index.html file, I don't know how to load it on localhost. solution is required.

Currently, we are loading the sub index.html file with the file protocol.

스크린샷 2022-12-27 오후 1 03 20

file path: (main) index.html path : www/index.html (sub) index.html path : www/world/wikitude_AR/inedex.html

version: cordova - 11 cordova ios - 6.2

Jung-Hey commented 1 year ago

Edit first line sentence wkwebkit => wkwebview

erisu commented 1 year ago

I think all you need to do is update the config.xml <content> tag to what you want...

In your example, it would be maybe:

<content src="world/wikitude_AR/inedex.html" />

And also remove the <base> tag from your html.

Jung-Hey commented 1 year ago

config.xml <content>태그를 원하는 대로 업데이트하기만 하면 됩니다...

귀하의 예에서는 다음과 같습니다.

<content src="world/wikitude_AR/inedex.html" />

또한 <base>HTML에서 태그를 제거하십시오.

How can I specifically modify this code? I already tried a similar method but it didn't work.

<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />

<platform name="ios">
    <preference name="scheme" value="app" />
    <preference name="hostname" value="localhost" />
    <allow-intent href="itms:*" />
    <allow-intent href="itms-apps:*" />
    <preference name="InAppBrowserStatusBarStyle" value="lightcontent" />
</platform>

breautek commented 1 year ago

By default, the root folder is the www folder.

So you can add sub folders inside www which contains web assets, including other HTML files.

Assume you have a www/subfolder/index.html file, you can make that as the initial launch file by changing the <content> preference:

<content src="subfolder/index.html" />

Or you can navigate to files using standard javascript... suppose to have the following files for example:

www/index.html
www/subfolder/index.html

While www/index.html is the loaded document, you can navigate to www/subfolder/index.html by using

window.location.href = "subfolder/index.html";

Likewise, while www/subfolder/index.html is the loaded document, you can go back up to www/index.html via:

window.location.href = "../index.html";

This isn't a Cordova Bug so I'll be closing this issue. Any further questions can be asked in our Discussions.