apache / cordova-ios

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

Links to the upper level URLs (../test/page.html) do not work on iOS 15-16 #1281

Closed sombatos closed 1 year ago

sombatos commented 1 year ago

Bug Report

Links to the upper level URLs (../test/page.html) work fine on iOS 12 but do not work on iOS 15-16.

Also the following JavaScript code does not work anymore (before it was redirecting to the specified page):

// window.location.href simply does not change and keep storing it's original value

window.location.href = "../test/page.html";
alert(window.location.href);

window.location.href = "file:///private/var/containers/Bundle/Application/D073O-CD734-BBDD-C64E/www/test/page.html";
alert(window.location.href);

Is this something that need to be fixed in cordova-ios? Or maybe there is some workaround?

Version information

iOS 15-16

XCode 13.0.x

<engine name="cordova-ios" spec="6.2.0" />
sombatos commented 1 year ago

Using window.WkWebView.convertFilePath('your/file/path') as recommended in some places does not help.

remoorejr commented 1 year ago
// Assuming localFile contains "file:///private/var/whatever..."
localFile = window.WkWebView.convertFilePath(localFile);
window.open(localFile)

Works for me Cordova iOS 6.2.0.

sombatos commented 1 year ago

Thanks. It works with window.open().

Hopefully window.open() does not create an extra window but simply changes location of the current window.

sombatos commented 1 year ago

Also one need to keep in mind that window.open() will work only as a result of clicking some link. It won't work if you just do:

<script>
window.open("../test/page.html");
</script>

Read more in this comment: https://github.com/apache/cordova-ios/issues/898#issuecomment-729450208

And the real user has to cause the event. For example emulating click event via $("#test").click() will not work.