Ad view: reliable exit on mobile/dApp browsers

window.close() is blocked in mobile and in-app wallet (dApp) browsers, which left
users stuck on the ad-view tab. Made "Back to dashboard" the primary action, and
"Close tab" now falls back to navigating to /my#earn when the browser refuses to
close the tab.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-08 07:17:39 -05:00
parent 8d9f56f68a
commit 50c0bd1aa7
2 changed files with 9 additions and 4 deletions
+6 -1
View File
@@ -82,7 +82,12 @@
} }
$('vClose').addEventListener('click', () => { $('vClose').addEventListener('click', () => {
window.close(); window.close();
setMsg('You can close this tab now.'); // window.close() is blocked in mobile and in-app (wallet dApp) browsers. If
// the tab is still here a moment later, take them back to the dashboard so
// they are never stuck on a tab they can't close.
setTimeout(() => {
if (!window.closed) { setMsg('Taking you back to your dashboard…'); location.href = '/my#earn'; }
}, 400);
}); });
(async () => { (async () => {
const info = await j('/api/my/viewinfo?token=' + token); const info = await j('/api/my/viewinfo?token=' + token);
+3 -3
View File
@@ -38,12 +38,12 @@
<span class="vmsg" id="vMsg">Loading the ad…</span> <span class="vmsg" id="vMsg">Loading the ad…</span>
<span class="vcheck" id="vCheck"><span class="prompt" id="vPrompt"></span><span id="vOpts"></span></span> <span class="vcheck" id="vCheck"><span class="prompt" id="vPrompt"></span><span id="vOpts"></span></span>
<span class="vdone" id="vDone"> <span class="vdone" id="vDone">
<button class="btn small" id="vClose" type="button">Close tab</button> <a class="btn small" href="/my#earn">Back to dashboard</a>
<a class="btn small sec" href="/my#earn">Back to dashboard</a> <button class="btn small sec" id="vClose" type="button">Close tab</button>
</span> </span>
</div> </div>
<iframe class="vframe" id="vFrame" sandbox="allow-scripts allow-same-origin allow-forms allow-popups" referrerpolicy="no-referrer" title="Advertiser site"></iframe> <iframe class="vframe" id="vFrame" sandbox="allow-scripts allow-same-origin allow-forms allow-popups" referrerpolicy="no-referrer" title="Advertiser site"></iframe>
</div> </div>
<script src="/assets/view.js?v=20260906m"></script> <script src="/assets/view.js?v=20260908a"></script>
</body> </body>
</html> </html>