There are a lot of questions, blog posts etc. to explain how to customise the beforeunload message a browser would emit upon navigating away from the page.
It all boils down to the following:
window.onbeforeunload = function() {
return 'Place your message here'
}
If you'd return an empty string, the browser's default, fully localized, message is returned:
window.onbeforeunload = function() {
return ''
}
I'm wondering if Javascript is able to do the inverse: getting/reading the default localized message. So for example in pseudo-code something like
const message = browser.messages.beforeunload
// Chrome EN : message = "Are you sure you want to leave this page?"
// Chrome NL : message = "Ben je zeker dat je deze pagina wilt verlaten?"
// Firefox : message = "This page is asking you to confirm that you want to leave..."
// ....
Related
I successfully call the getAttachmentsAsync function from office.js in the webbrowser, all attachments are returend, but in the client, the function returns "failed" and - sorry a german error message - "Dieser Vorgang wird nicht unterstützt" what means "This process is not supported".
I've implemented the call on base on this documentation:
https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/add-and-remove-attachments-to-an-item-in-a-compose-form
var item = Office.context.mailbox.item;
var options = { asynContext: { currentItem: item } };
item.getAttachmentsAsync(options, function (result) {
console.log(result.error.message);
});
To reproduce the error:
create a web addin with the code above (for edit mode)
open new email, attach some files
and call the code
The call returns the following:
code: 5000
name: Hostfehler
message: Dieser Vorgang wird nicht unterstützt
Needing a little help in here:
Context: I am able to log in using email no problem. Redirect and url_for working flawlessly.
When I login with google, though... It is logging in, but not redirecting, thus, not reloading the page, not showing the logout button and so on.
relevant code:
python flask authorized login is "http://localhost:5000/oauth2callback":
btw: I know I shouldn't use google's id, I am still testing it.
#app.route('/oauth2callback/<id>/<nome>/<email>', methods=['POST'])
def oauth2callback(id, nome, email):
#print(f'o ID é {id}, o nome é {nome} e o email é {email}')
try:
if User().query.filter_by(email = email).first():
usuario_google = User().query.filter_by(email = email).first()
print(usuario_google)
login_user(usuario_google)
print('usuario logado')
return redirect(url_for('home', next=request.url))
else:
sessao_google = User(username=email, email=email, nome=nome)
senhas_google = Senha(senha='')
db.session.add(sessao_google)
db.session.commit()
db.session.add(senhas_google)
db.session.commit()
print('Registrado')
return redirect(url_for('login', next=request.url))
except Exception as e:
raise redirect(url_for('login'))
finally:
pass
return redirect(url_for('home'))
I will add javascript just in case:
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
var xhttps = new XMLHttpRequest();
var novaurl = 'http://localhost:5000/oauth2callback/'+profile.getId()+'/'+profile.getName()+'/'+profile.getEmail();
console.log(novaurl)
xhttps.open('POST', novaurl);
xhttps.send();
}
Thank you for any ideas/help.
I have a question about cakephp and sweet alert.
Are you able to replace, and instead of the standard Flash Message, give Sweet Alert? I have already managed to give Sweet Alert the confirmation of deleting the record, but I do not know how I can handle it when it saves data (for example in edit.ctp) and after saving it brings me to index.ctp (here I want Sweet Jump to pop out).
At the confirmation of removal I used cakephp-3-sweet-alert-helper by falco442.
This is my edit method:
public function edit($id = null)
{
$contact = $this->Contacts->get($id, [
'contain' => ['Users', 'Departments']
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$contact = $this->Contacts->patchEntity($contact, $this->request->getData());
if ($this->Contacts->save($contact)) {
$this->Flash->success('Contact saved');
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The contact could not be saved. Please, try again.'));
}
$users = $this->Contacts->Users->find('list', ['limit' => 200]);
$this->set(compact('contact', 'users'));
}
How can I replace this $this->Flash->success('Your Success Message.'); with an alert from SWAL ?
You should leave controller code as is.
But you should update flash message templates at src/Template/Element/Flash/.
By default, CakePHP outputs <div>, you should replace it with <script>swal("Hello world!");</script>
here you can set sweet alert javascript
Path: src/Template/Element/Flash
success.ctp
error.ctp
first thing use sweet alert js and css
swal({
title: "Success",
text: "Successfully created",
icon: "success",
});
I have a HTML form with a textarea in it.
When entering a text with some enters in it, my Javascript malformes and wont load.
The forms submits to a PHP script that outputs the javascript below.
How can I fix this?
function confirmsms() {
var redirect = confirm("Er zullen 791 smsjes worden verzonden, klik op OK om door te gaan");
if (redirect == true) {
window.location.href = 'send.phpregio=%&vakgebied=Loodgieter&disciplines=&bericht=aasdasd
asdasda
sdasdasd';
}
}
</script>
Change to this:
function confirmsms() {
var redirect = confirm("Er zullen 791 smsjes worden verzonden, klik op OK om door te gaan");
if (redirect == true) {
window.location.href = 'send.php?'
+ 'regio=%&vakgebied=Loodgieter&disciplines=&'
+ 'bericht=aasdasdasdasdasdasdasd';
}
}
UPDATE: It seems that your php variable $bericht has line returns in it. Let's sanitize the variable to remove spaces and line returns like so:
$bericht = str_replace(array(' ', "\n", "\t", "\r"), '', $bericht);
Then you can use your code as before. To be safe, I would sanitize all your php variables that are going to be dropped right into javascript.
<HTML>
<HEAD>
<script type=\"text/javascript\">
function confirmsms() {
var redirect = confirm(\"Er zullen $count smsjes worden verzonden, klik op OK om door te gaan\");
if (redirect == true) {
window.location.href = 'send.php?regio=$regio&vakgebied=$vakgebied2&disciplines=$disciplines&bericht=$bericht'; }
}
Looks like the problem is you are not encoding your URL! As in your problem you are passing data using GET method your data will be the part of the URL itself!
Simply use encodeURI() before sending! So your code should look like
function confirmsms() { var redirect = confirm("Er zullen 791 smsjes worden verzonden, klik op OK om door te gaan"); var encodedValue = encodeURI("YOUR TEXTAREA VALUE HERE"); if (redirect == true) { window.location.href = 'send.php?VAR1=VAL1&VAR2=VAL2'; }}
And at the back-end you can decode URL using string urldecode ( string $str )
Hope you this is what you are looking for!
This question already exists:
Blocking a user from logging in with a certain permission level and then an alert displaying to let them know why
Closed 7 years ago.
I am trying to figure out how to deny a user access from signing in to my site unless they have been approved. I am making my site private to only those I allow to join. Anyone can register, but once they do they are given a permission/group level of 1 or 'bench'. Once I accept the user and change the permission level, then they are able to login.
As of now, I am stopping the level/group 1 users with a redirect back to the index page(where they sign in at). However, I want to not allow them to move forward to the next page at all. The reason being is I want to display some sort of pop up alert displaying a message that I created.
I'm not sure if I can do this with validation or the way I am trying to do it. I added on to my login code and am attempting to put my permission code I had on the signed in page to try to stop it from the start. Basically, in an attempt that if the user tries to log in, the script dies once it sees that the permission level is at the group 'bench'. Then a pop alert displays saying why.
I'm not having much success with it. My group/permission levels have a name and ID. I have tried putting both in this single quotatiob's like 'bench' and '1', but I get the same error with both.
Fatal error: Call to a member function hasPermission() on a non-object in /home4/pfarley1/public_html/example.com/index.php on line 12
I'm trying to log them in like this...
<?php
if(Input::exists()) {
if(Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array(
'username' => array('required' => true),
'password' => array('required' => true)
));
// added this line in
if($user->hasPermission('1')) {
die($permissionError);}
if($validation->passed()) {
$user = new User();
$remember = (Input::get('remember') === 'on') ? true : false;
$login = $user->login(Input::get('username'), Input::get('password'), $remember);
if($login) {
Redirect::to('userIndex.php');
} else {
$tryagain = '<span class="signinpanel">' . "The information you entered did not match our records." . '</span>';
}
} else {
foreach($validation->errors() as $error) {
echo $error, '<br>';
}
}
}
}
?>
My permission code for users..
public function hasPermission($key) {
$group = $this->_db->get('groups', array('id', '=', $this->data()->group));
if($group->count()) {
$permissions = json_decode($group->first()->permissions, true);
if($permissions[$key] == true) {
return true;
}
}
return false;
}
What am I doing wrong this this or is there a better way to do this?
Edit:
The last question wasn't specific enough, so I added info and there has been modification to the code in how I was trying to do this.
What is $user on line 12?
if($user->hasPermission('1')) {
Error message is pretty explicit.