javascript - window.location or document.location [duplicate] - javascript

This question already has answers here:
What's the difference between window.location and document.location?
(17 answers)
Closed 10 years ago.
Is there any difference between the location property of the window object versus the location property of the document object?
window.location || document.location // That is the question.
Are their properties identical?
Do they have differing browser support?

These two objects are identical:
console.log(window.location === document.location) // true
They both refer to Location object.

window.location represent position in current view of page in browser window
and document.location represents position in currently displaying full document/page
e.g in http://www.nationalgeographic.com/ upto DAILY NEWS section is window and full page scrolled down till end is document

Related

JQuery not initializing variable [duplicate]

This question already has answers here:
Why does jQuery or a DOM method such as getElementById not find the element?
(6 answers)
Closed 2 years ago.
I have the following piece of code in my javascript file(helper.js):
var a = $('li')
$(window).keydown(function(e) {
\\whatever
})
it is supposed to select all tags in my html file and store in in a, however when I use this code, it a is null(which it shouldn't be). when I change my code to:
$(window).keydown(function(e) {
var a = $('li')
\\whatever
})
a is initialized correctly. Does anyone knows why? I am using jquery 3.3.1.
If you are dealing with the DOM (Document Object Model), use $(document).
If you are dealing with how user interact with the window, screen and so on, use $(window)
Here is a link for better understanding window and document
Window vs Dom

Windows.open append the url to my current page url [duplicate]

This question already has answers here:
Window.open url rewrites the base url two times [closed]
(2 answers)
Closed 2 years ago.
Uder my app ; i m costomising an url to open itin a new window :
myURL = `http://www.google.fr/BB/196?ACTIVITYTEAM=2632&ALLIANCE=FSMG2212&ACTIVITY=VENDEUR/`
weh using
window.open(myURL) ; it doesn't open me that yurl , but i's opening this one :
https://www.google.fr/?http://www.google.fr/BB/196?ACTIVITYTEAM=2632&ALLIANCE=FSMG2212&ACTIVITY=VENDEUR/
as you can see it inject google one extra time in the begining , i want to evitate this
Suggestions ?
i don't understand why is this a problem, your pop up is showing an error?
Anyway, I think you could try this:
var w1 = window.open();
w1.location.href='http://www.google.fr/BB/196?ACTIVITYTEAM=2632&ALLIANCE=FSMG2212&ACTIVITY=VENDEUR/';
Hope it helps you :)

How to check for a specific word in the URL before running script? [duplicate]

This question already has answers here:
How to make a script redirect only once every time an appropriate page loads?
(4 answers)
Closed 3 years ago.
I have the current script to amend a link in the URL bar
(function() {
'use strict';
location.replace(location.href.replace("www.reddit.com", "old.reddit.com"));
})();
I'd want it to check if the URL has the word "old" before running the remainder of the script. How do I do this?
You can check the index of the word old by considering the URL as a normal string.
if(location.href.indexOf('old') > -1) {
// do something
}
It is simple as that.

how to redirect with jquery a page to another when a counter ends? [duplicate]

This question already has answers here:
How do I redirect to another webpage?
(58 answers)
Closed 4 years ago.
Hello programmers this is my question today, what function in jquery do i need so when a counter reach the number 100 that page is redirected to the main menu?
Check the counter's value with an if statement and if the value is 100, then simply:
window.location.href = 'http://example.com';
There is no need for JQuery in this.

open multiple links in a new windows at once [duplicate]

This question already has answers here:
$window to open multiple links blocked by pop up
(2 answers)
Closed 8 years ago.
how to avoid the link to be blocked by browser popup?
my demo work but it only open the first link, I wonder.. I used foreach..
http://plnkr.co/edit/m8m2I9dqE2kF1H1nzxJT
Added value, key to CB function args and used that to get at the link value, also added the window name attribute telling open function to open blank window each time:
angular.forEach($scope.links, function(value, key){
$window.open("link.html/?" + value.link, '_blank');
});
$scope.links.link was returning "undefined" in that location.

Categories

Resources