Javascript 警报 - 删除“??? 上的页面说”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7996785/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript Alert - Removing "The page at ??? Says"
提问by Drew
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".
我有一个表单,我正在使用 Javascript 来验证表单,所以如果您将一个字段留空,它会提醒“请填写您的姓名”。
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.comsays: Please fill in your name
如果我直接转到链接,它可以完美运行。但这有点像一个小部件,所以我使用 iFrame 将它嵌入到其他站点中。当我嵌入它时,并单击带有空字段的提交,它说:http://www.example.com 上的页面说:请填写您的姓名
Is there a way to get rid of that?
有没有办法摆脱它?
回答by Quentin
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.
如果你想要一个没有它的对话框,那么你必须在你的页面中使用 HTML 元素来伪造它。
回答by Nejuf
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.
对于那些仍然希望使用本机警报/确认的人来说,通过反网络钓鱼实施并不难。这是因为 iframe 可以编辑父级并访问它的作用域。
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).
这样做的原因是因为new Function('')不会创建闭包,而是使用定义 Function 的范围(通过 parent.Function)。
回答by webtech
You can use some custom alert plugin. For example http://stefangabos.ro/jquery/zebra-dialog/
您可以使用一些自定义警报插件。例如http://stefangabos.ro/jquery/zebra-dialog/