问题
I have a form and I am using Javascript to validate the form so if you leave a field blank it will alert "Please fill in your Name".
If I go to the link directly, it works perfectly. But this is kind of like a Widget so I am using an iFrame to embed it into other sites. When I embed it, and click Submit with an empty field it says: The page at http://www.example.com says: Please fill in your name
Is there a way to get rid of that?
回答1:
No, there isn't. It is an anti-phishing feature.
If you want a dialog without it, then you have to fake it using HTML elements in your page.
回答2:
For those who are still looking to use the native alert/confirm, it's not that hard to get past the anti-phishing implementation. This is because the iframe can edit the parent and access it's scope.
Try this:
parent._alert = new parent.Function("alert(arguments[0]);");
parent._alert('Test!');
The reason this works is because new Function('') does not create a closure and instead uses the scope of where Function is defined (via parent.Function).
回答3:
You can use some custom alert plugin. For example http://stefangabos.ro/jquery/zebra-dialog/
来源:https://stackoverflow.com/questions/7996785/javascript-alert-removing-the-page-at-says