iframe模态未能关闭

时间:2012-09-06 07:44:28

标签: javascript iframe modal-dialog

我使用从浏览器书签中生成的iframe模式,从用户正在查看的网页收集信息。

用户添加到书签工具栏中的代码在点击时会触发书签:

javascript:(function(d){var%20modal=document.createElement('iframe');modal.setAttribute('src','http://9ammusic.com/test/bookmarklet.html?url='+encodeURIComponent(window.location.href)+'&page_title='+document.title);modal.setAttribute('scrolling','no');modal.className='modal';document.body.appendChild(modal);var c=document.createElement('link');c.type='text/css';c.rel='stylesheet';c.href='//9ammusic.com/css/iframe.css';document.body.appendChild(c);}(document));

此代码以显示问题的方式工作

100次中有95次这样可以正常工作并且它应该关闭,但有时,关闭链接根本不起作用 - 是否有一种不同/更好的方法可以关闭这样的模态?

要测试请转到下面的链接并尝试书签 - 它在Firefox中关闭但在Chrome中没有关闭:

http://www.ebay.co.uk/itm/JEFF-BANKS-BESPOKE-BLACK-RED-PINSTRIPE-100-WOOL-MENS-SUIT-36S-DRY-CLEANED-/330789478348?_trksid=p5197.m1992&_trkparms=aid%3D111000%26algo%3DREC.CURRENT%26ao%3D1%26asc%3D14%26meid%3D1848697403629550114%26pid%3D100015%26prg%3D1006%26rk%3D1%26#ht_1830wt_1163

1 个答案:

答案 0 :(得分:0)

由于某种原因这很有用,所以现在一切都很好,使用表单代替链接:

<form method=post action=<?=$_GET['url']?> target="_parent">
<input type=submit value="X Close Window"></form>