0

ブックマークレットから iframe を作成し、内部に HTML を追加してページのコンテンツを表示しています。

iframe を閉じるのに問題があります。

ユーザーは、他の Web ページを表示しているときにブックマークレットをクリックします。

iframe が開かれた target="_parent" を使用して元の URL に投稿できますが、一部のサイトでは URL の投稿が許可されていないため、これは問題です。さらに、ユーザーが元の場所に移動するために戻るボタンを 2 回操作する必要があるためです。ブックマークレットをクリックする前に。

これはブックマークレットのコードです: (テスト用に動作します)

javascript:(function(d){
  var%20modal=document.createElement('iframe');
  modal.setAttribute('src','http://9ammusic.com/test/bm2.html?url='+encodeURIComponent(window.location.href)+
  '&page_title='+document.title);
  modal.setAttribute('scrolling','no');
  modal.setAttribute('name','my_modal');
  modal.className='modal';
  document.body.appendChild(modal);

  var%20c=document.createElement('link');
  c.type='text/css';
  c.rel='stylesheet';
  c.href='//9ammusic.com/css/iframe.css';
  document.body.appendChild(c);
}(document));

現時点では、次のwindow.location.hrefように取得している URL を使用してフレームを閉じています。

<form method=post action=<?=$_GET['url']?> target="_parent">

しかし、これはまったく理想的ではありません。親ウィンドウにまったく影響を与えずに iframe を直接閉じる方法はありますか?

4

0 に答える 0