我正在使用 cordova 3.5
我的 iframe 设置如下:
<iframe src="http://localhost/test/index.html" style="width:100%;height:90%" onLoad="checkforclose(this);"></iframe>
JS如下:
<script type="text/javascript">
function checkforclose(pageURL) {
var urlFrame = pageURL.contentWindow.location; //WORKS
alert(urlFrame); //WORKS
alert(urlFrame.indexOf('test')); //DOESN'T WORK EVEN FOR ANY VALUE - RETURNS UNDEFINED
}
</script>
该片段有效,因为前两行有效。但第三个没有。 更重要的是,在 JSFiddler 中可以工作。 我对此感到非常迷失。
提前致谢
最佳答案
尝试alert(urlFrame.href.indexOf('test'));
它不起作用的原因是您正在 window.location (urlFrame) 对象上调用indexOf。它抛出一个错误,因为indexOf()不是window.location的函数属性。
关于javascript - 在 javascript 中使用 url 和字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26413187/