Open polianomartini opened 6 years ago
Hm, works for me when I run it in the JS console:
Do you have a screenshot?
I forgot to quote!
The import is done in a given HTML body and the access by an iframe. I'm using the expression "parent.swal", which in the old version works, but not in this new one, returning the error.
Here the same problem. I use also parent.swal in an iframe which has worked in the old (1.x.x) version. :confused:
Please fix that.
edit: It happens only on extended configurations. Alerts like the following does work:
parent.swal('Info!', 'Some description.', 'info');
I'm also affected. I've a workaround. Define a function like this in your parent:
function myswal(value) {
v = {}; for (var key in value) { v[key] = value[key]; };
swal(v);
};
and call this function from the iframe.
Any news? I noticed other users with the same problem.
More information (tested in version 2.0):
The reference (import) of the library is in the main body of the page and I'm calling the SweetAlert function on a button that is inside an iframe.
Image https://uploaddeimagens.com.br/imagens/test-png--121
This is running:
mainSystemFrame.swal ("Oops", "Something went wrong!")
However, it does not run when I use the "extended" call:
mainSystemFrame.swal ("Are you sure you want to do this?", {
buttons: ["Oh noez!", "Aww yiss!"]
});
The error generated is:
Uncaught SweetAlert: 2nd argument ('[object Object]') is invalid
@jordeu
It does not solve when using premises.
Ex:
swal("Click on either the button or outside the modal.")
.then((value) => {
swal('The returned value is: ${value}');
});
I've done some digging and think I found the cause of this bug:
When swal
is called from inside an iframe, the condition prototype === Object.prototype
in this line seems to return false
.
On the other hand, when used outside of an iframe (or the console), prototype === Object.prototype
returns true
.
This results in isPlainObject
returning false
and an error is thrown, because swal assumes the parameters are invalid.
Apparently Object prototypes are different in different frames, @t4t5 do you know more about this?
PRs are welcome 😃
Hi,
If someone still has a similar problem i've made like @jordeu but with some changes tha allows use o promises
Ex:
window.mySwal = function(option){ jsonOptions = JSON.stringify(option); return swal(JSON.parse(jsonOptions)); };
Hi, my dear!
I use SweetAlert in a project, but I noticed that there were some changes.
Before, I imported a JS file and a CSS into the body of HTML. I downloaded the latest "sweetalert.min.js" file and imported it as before but I'm having trouble using it.
The call below runs successfully:
But this other:
... the following error occurs:
I'm doing something wrong?