如何将网页加载到新窗口中并向其中注入JavaScript代码? [英] How can I load a web page into a new window and inject JavaScript code into it?

查看:67
本文介绍了如何将网页加载到新窗口中并向其中注入JavaScript代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JavaScript打开新窗口(加载例如 http://www.google.com ),然后将此代码插入/插入到正文中:

Using JavaScript, how can i open a new window (loading, say, http://www.google.com in the process) and inject/insert this code into its body:

<script type="text/javascript">alert(document.title);</script>

我知道如何打开一个新窗口,但是我不知道如何将脚本添加到新窗口并运行它:

I know how to open a new window, but i don't know how to add the script to the new window and run it:

var ww = window.open('http://www.google.com');


推荐答案

。这将违反大多数人(全部?)实施的 相同来源政策 。浏览器以保护其用户。

No. This would violate the same origin policy implemented by most (all?) browsers to protect their users.

想像一下这是否可行:您可以说服用户访问您的网站,打开一个新窗口,例如将其银行网站加载到其中,然后注入代码以窃取其凭据。然后继续窃取他们的钱,身份等...

Imagine if this were possible: You could convince users to come to your site, open a new window with, say, their bank's website loaded into it, and inject code to steal their credentials. Then proceed to steal their money, identity, etc...

不好,是吗?因此,非常非常高兴不可能。

Not good, eh? So be very, very glad it isn't possible.

这篇关于如何将网页加载到新窗口中并向其中注入JavaScript代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆