I am currently loading web views using HTML
file. And web functions are handled in js
file. This is not a problem.
But my problem is the backButton. I check if there is a page to go back to. So we used document.referrer
to show webviews using existing servers.
But it doesn't work because it's used inside iOS while creating the iOS hybridApp
.
So I checked if the history.back()
worked. It works. There's a page to go back to.
There are pages that need to be returned, but document.referrer
not work.
Move from main page to detail page in html include js file
location.href = './Detail.html'
Back button function in the header of Common.js
file
alert(document.referrer) // return empty
if (document.referrer) {
history.back();
} else {
location.href = "./Main.html"; // only can do
}
The two html files(Main,Detail) use a common header. The function is in the Common.js
file. And I'm using Swift5
Main.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover, shrink-to-fit=no">
<meta name="referrer" content="always">
Detail.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover, shrink-to-fit=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="referrer" content="always">
How can we solve this problem?
Thanks in advance.