
Apu
March 13, 2022 ›
#difference
›
#Javascript
❌
Difference between window.open and window.location.href
If you want to know what the difference is between window.location.href and window.open and which one is best to use , then in this article, I shall explain the difference.
What is window.location.href ?
window.location.href is not a method or function. It's a property that allow us to get the url of current browser.
Get current browser URL
function myFunction1(){ document.write(window.location.href) ; }Try it Yourself »
window.location.href opens a url in the same window in which the js code is called.
Example of window.location.href property
function myFunction2(){ window.location.href="https://www.example.com"; }Try it Yourself »
What is window.open?
window.open is a method that will open the url in a new browser.
Example of window.open() method
function myFunction1(){ window.open("https://www.example.com"); }Try it Yourself »
save
listen
AI Answer
Difference between window.open and window.location.href
0
If you want to know what the difference is between window.location.href and window.open …
asked
Apu
0 answers
2915
If you want to know what the difference is between window.location.href and window.open …
Answer Link
answered
Apu