我一直在盡我所能解決這個問題,但我真的找不到有什麼問題。我對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>
我真的希望有人可以幫我解決=)謝謝!