im writing a small forum template for others to use, but since repl db is persistent in the actual website itself and not in the cover page, I want to redirect to another webpage informing they need to open the repl in a new tab.
i tried searching for answers (read tens of hundreds of topics!) and couldn’t find anything.
To detect if it’s in the cover page, I’ve seen window==window.parent be used. It checks if the current window (i.e. the page embed) is the same as the parent window (i.e. the main page).
if (!(window.location.host == "forum-template.joecooldoo.repl.co/")) {
// If the website host is not 'forum-template.joecooldoo.repl.co/'
window.open("https://forum-template.joecooldoo.repl.co/", '_blank')
// if you want to open in the same tab, use:
// window.location.href = "https://forum-template.joecooldoo.repl.co/"
}
If you want me to explain further or need more help, feel free to ask!
<script>
if (String(window.location).split(".")[1] == "id") {
window.open(window.location) // Open the new tab because it is in the cover page
} else {
continue // It's in a new tab already
}
</script>
Unfortunately, this is a template and it’s probably going to be forked several times. I DO have a global Flask template variable that reports the host URL though. Could I replace the URL using the global template variable? Also, this code seems to me that it will activate also if it’s in an iframe from a different website. I want the message to only appear when viewing through the Repl’s cover page.
Would I replace the code with something like this?
if (window.location.host == 'replit.com') {
window.open('{{host_url}}', '_blank')
//"host_url" template variable gets replaced when a user makes a request to the system
}
var coverPage = window.location.hostname.split('.')[1] === 'id'
if (coverPage == true) {
// If on cover page
window.location.href = "path/to/new/webpage";
}
This will ensure that the code works for any user.