简体   繁体   中英

Does exist a way to redirect and show a javascript message?

After the user update a register I'd like to redirect him to another page and there I'd like to show a javascript message (alertfy.notify()) telling that the register was successfully updated.

I don't know if exists a way to write a script tag dynamically in the redirected page.

Please, I don't want to pass a variable in the querystring.

If you use PHP, you could do for example:

<?php
session_start();

function storeMessage() {
    $_SESSION['message_registered'] = 'Your message...';
}

function getRegisterMessage() {
    return $_SESSION['message_registered'];
}
?>

And in javascript-only:

function setMessage(name, msg) {
    localStorage.setItem('message_' + name, msg);
}

function getMessage(name) {
    return localStorage.getItem('message_' + name, msg);
}

// at register form succesful submit
setMessage('registered', 'Thank you for creating an account!');

// at the page you want to get the message
var msg = getMessage('registered');
alert(msg);

You could also create something like a token in javascript. Every time when a tab opens with a page of your site, you create a token with javascript. Only the right tab with the right token gets the message. So the token is stored in the 'javascript memory' of each tab/window.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM