Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

javascript - JavaScript中的window.location.href和window.open()方法(window.location.href and window.open () methods in JavaScript)

JavaScript中的window.location.hrefwindow.open ()方法有什么区别?

  ask by masif translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

window.location.href is not a method, it's a property that will tell you the current URL location of the browser.

(window.location.href 不是一个方法,它是一个告诉你浏览器当前URL位置的属性。)

Changing the value of the property will redirect the page.

(更改属性的值将重定向页面。)

window.open() is a method that you can pass a URL to that you want to open in a new window.

(window.open()是一种方法,您可以将URL传递给要在新窗口中打开的URL。)

For example:

(例如:)

window.location.href example:

(window.location.href示例:)

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

window.open() example:

(window.open()示例:)

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


Additional Information:

(附加信息:)

window.open() can be passed additional parameters.

(window.open()可以传递其他参数。)

See: window.open tutorial

(请参阅: window.open教程)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...