How do I decide whether to open my local web page window with window.open
or window.location.href
?
Asked
Active
Viewed 1,098 times
2

MarredCheese
- 17,541
- 8
- 92
- 91

MDLS Itec
- 21
- 3
-
Possible Duplicate: https://stackoverflow.com/questions/7077770/window-location-href-and-window-open-methods-in-javascript – Naveed Ramzan Mar 22 '19 at 04:29
-
Possible duplicate of [Window.location.href and Window.open () methods in JavaScript](https://stackoverflow.com/questions/7077770/window-location-href-and-window-open-methods-in-javascript) – soorapadman Mar 22 '19 at 05:39
2 Answers
1
Simply,
window.open()
will open a new window for your passing URL in side the parentheses.
window.location.href
will redirect you to the passing URL with in the same window.

Bathiya Seneviratne
- 182
- 2
- 13
-
I mean use jQuery or javascript in the local Web Page. Can you have a good idea? Thank you. – MDLS Itec Mar 22 '19 at 04:55
-
According to my knowledge I think it's better to use javascript with in a separate file in your project folder. But anyways it depends on your taste :) – Bathiya Seneviratne Mar 22 '19 at 05:24
-
You can use `window.open('
', '_self')` to open a url in the same tab https://developer.mozilla.org/en-US/docs/Web/API/Window/open – Ernesto Alfonso Jul 11 '23 at 06:26
0
if window.opener == null
// open by window.location.href
else
// open by window.open

MDLS Itec
- 21
- 3