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

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.

Related

JavaScript Puppeteer: Check if element is present on webpage [duplicate]

This question already has answers here:
How can I check if selector exists in Puppeteer?
(8 answers)
Closed 7 months ago.
I am using the JavaScript Puppeteer API. I need to check if an element(a button) is available on a webpage so I am able to click it without the worry of it giving me an error. Sometimes the element won't appear, so knowing it's there will help me to know when to click it.
Thanks for any help!
The Page.$ function will allow you query the page for an element by its selector. If it is there it will return an "element handler" if it is not present on the page it will return null. Remember to await it since this like most puppeteer functions is async.
https://pptr.dev/api/puppeteer.page._
Example:
const element = await page.$('.my-selector');
if(element !== null){
//click on it
}
`

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.

javascript events not working with Chrome Extension , why ! :/ [duplicate]

This question already has answers here:
Port error while changing chrome extension from manifest v1 to v2
(2 answers)
Closed 8 years ago.
HTML // code
input id ="submit_btn" type="submit" value="find" onclick="goto();"
Javascript / code
function goto()
{
if (document.getElementById("s_keyword").value != "") {
var url = ("https://www.youtube.com/results?search_query=" + document.getElementById("s_keyword").value);
var site = window.open(url, '_blank');
site.focus();
}
};
it never enters into goto function !
Chrome extensions don't support inline events. Add the event listener in your JavaScript, and it'll be fine:
document.getElementById('submit_btn').addEventListener('click', goto);
You may want to avoid using goto as your function's name too. It may be a reserved keyword.

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

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

Categories

Resources