1. ホーム
  2. javascript

[解決済み] クリックするとウィンドウが開き、サイズが指定できる

2022-12-06 05:47:40

質問

このようなリンクがあります。

<a href="/index2.php?option=com_jumi&amp;fileid=3&amp;Itemid=11" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,')

新規に開くウィンドウを特定のサイズで開きたい。高さと幅はどのように指定するのですか?

どのように解決するのですか?

<a href="/index2.php?option=com_jumi&amp;fileid=3&amp;Itemid=11"
   onclick="window.open(this.href,'targetWindow',
                                   `toolbar=no,
                                    location=no,
                                    status=no,
                                    menubar=no,
                                    scrollbars=yes,
                                    resizable=yes,
                                    width=SomeSize,
                                    height=SomeSize`);
 return false;">Popup link</a>

widthとheightは単位なしのピクセルです(width=400ではなくwidth=400px)。

ほとんどのブラウザでは、改行せずに記述しないと動作しません。変数の設定後は、すべてを一行で記述してください。

<a href="/index2.php?option=com_jumi&amp;fileid=3&amp;Itemid=11" onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=SomeSize,height=SomeSize'); return false;">Popup link</a>