JavaScript の window.location.href および window.open() メソッド 質問する

JavaScript の window.location.href および window.open() メソッド 質問する

JavaScript の メソッドwindow.location.hrefとメソッドの違いは何ですか?window.open ()

ベストアンサー1

window.location.hrefはメソッドではなく、ブラウザの現在の URL の場所を示すプロパティです。プロパティの値を変更すると、ページがリダイレクトされます。

window.open()新しいウィンドウで開きたい URL を渡すことができるメソッドです。例:

window.location.href の例:

window.location.href = 'http://www.google.com'; //Will take you to Google.

window.open() の例:

window.open('http://www.google.com'); //This will open Google in a new window.

追加情報:

window.open()追加のパラメータを渡すこともできます。参照:window.openチュートリアル

おすすめ記事