ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What is the diffrence between Window.location.href () and Window.open () ?

user-image
تم إضافة السؤال من قبل Zaid Rabab'a , Software Development Team Leader , Al-Safa Co. Ltd.
تاريخ النشر: 2014/01/28
Shakeel Ishaq
من قبل Shakeel Ishaq , Senior Project Manager

window.location.href is not a method, it's a property that will tell you the current URL location of the browser. Setting the property to something different will redirect the page.

Example:

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

 

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

Example:

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

Mahmoud Elmahdi
من قبل Mahmoud Elmahdi , UX/UI Designer, Web Developer , ikantam.com

window.location.href is not a method, it's a property that will tell you the current URL location of the browser. Setting the property to something different 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. For example:

 

window.location.href example:

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

 

window.open() example:

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

Arun Raj Alampatta
من قبل Arun Raj Alampatta , Senior Software Engg. , Orion India Systems

Window.location.href using to redirect specified page in same window.

Window.Open it open a new window or new tab and we can manage nature, height, width,etc.

Samir Alkhatib
من قبل Samir Alkhatib , IT Support Engineer , Vianeos

one is a property and the other is method :)

Muhammad Majid Saleem
من قبل Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

Key differences between window.location and window.open are:

Window.Open

- It is a method.

- It accepts few parameters like window.open(URL,name,specs,replace).

- It accepts a URL and opens it to a new window.

- For example http://www.w3schools.com/jsref/met_win_open.asp

 

Window.location.href

- It is not a method but a string representation.

- It returns the location of the current page.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟