如何从外部 javascript 文件中访问在另一个地方声明的某个变量?
假设在一个 html 文件中我有以下内容
<head>
<script>
var a = 'something';
</script>
<head>
<body>
<iframe src="otherfile.html"/>
</body>
在 otherfile.html 的部分中,我有
alert(a);
我如何确保收到一条提示消息“某事”?
我认为Google Adsense就是这样做的,他们的代码是:
<script type="text/javascript"><!--
google_ad_client = "youdontneedtoknowthis";
google_ad_slot = "5404192644";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
脚本中如何http://pagead2.googlesyndicate.com/pagead/show_ads.js http://pagead2.googlesyndication.com/pagead/show_ads.js知道这些变量(例如 google_ad_client)吗?
没关系。
All <script>
页面中的块共享相同的上下文和变量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)