我一直在尽我所能解决这个问题,但我真的找不到有什么问题。我对JavaScript没有真正的经验,所以它可能是我缺少的基本东西。onClick parent getElementById.click();不在CHROME中工作
现在,我复制代码后,我发现允许除IE浏览器注册click();它在除了Chrome之外的每个浏览器都能很好地工作。我测试了IE,FF,Safari和Opera,他们都在工作。
我的设置是我有一个带有按钮的iframe,它应该可以激活父级中的shadowbox库。
我的主页(index.html的)脚本是:
<head>
//shadowbox linking
<link rel="stylesheet" type="text/css" href="shadowbox/shadowbox.css">
<script type="text/javascript" src="shadowbox/shadowbox.js"></script>
<script type="text/javascript">
Shadowbox.init();
</script>
//included based on what I found online to enable the click(); method to work in browsers besides IE)
<script type="text/javascript">
if(typeof HTMLElement!='undefined'&&!HTMLElement.prototype.click)
HTMLElement.prototype.click=function(){
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt); }
</script>
</head>
<body>
<a id="web1" href="http://www.google.com/" rel="shadowbox[gallery]"></a>
<a id="web2" href="http://www.yahoo.com/" rel="shadowbox[gallery]"></a>
<iframe src="frame.html">You can't see
iframes.</iframe>
</body>
我在iframe(frame.html)链接:
<a href="#" onClick="parent.document.getElementById('web1').click();">Link1</a>
<a href="#" onClick="parent.document.getElementById('web2').click();">Link2</a>
我真的希望有人可以帮我解决=)谢谢!