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

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 :)

Related

Modify url and update with anather url using Javascript [duplicate]

This question already has answers here:
How to replace host part of a URL using javascript regex
(3 answers)
Closed 1 year ago.
I have below url
Input
url1 = https://www.example1.com/xyz/abc/123
I need modified above url and replace only domain to https://www.modifiedexample.com/
Output url2= https://www.modifiedexample.com/xyz/abc/123
This should work in all the browser
How to achieve this in Javasript in simple and efficient way
You can try URL API:
const url = new URL('https://www.example1.com/xyz/abc/123');
url.hostname = 'www.modifiedexample.com';
console.log(url.href); // https://www.modifiedexample.com/xyz/abc/123

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.

Get the query string value from a URL using javascript [duplicate]

This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 6 years ago.
I have a URL like
http://something.com?acess_token=ashv6786sdjfhjd
When I click on that link, how to get the access_token from that link using Javascript?
Try :
var Yoururl= "http://something.com?acess_token=ashv6786sdjfhjd";
var acessToken=Yoururl.split('?')[1].split('=')[1];
Working Fiddle
For url parameter see old so question from given link.
Get url parameter via jquery
If you want the value of the access_token you mean this:
ashv6786sdjfhjd
Then here's a quick solution. Hope it helps!
var str = "http://something.com?acess_token=ashv6786sdjfhjd.when";
var accessToken = str.split("=")[1].split(".")[0];
console.log(accessToken);

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.

PHP $_Get and JQuery .load [duplicate]

This question already has answers here:
Encode URL in JavaScript
(22 answers)
Closed 8 years ago.
I want to load another page via Javascript like this
$("#resultarea").load("searchresults.php?searchstring=" + $("#searchbox").val());
in searchresults.php, a single statement
echo $_GET["searchstring"];
what I type in searchbox appears when searchresults.php is loaded except when I add space and another word, no thing appear at all. I heared it can be done by encoding or somewhat, I searched but didn't find a solution.
Try encodeURIComponent:
var encodedValue = encodeURIComponent($("#searchbox").val());
$("#resultarea").load("searchresults.php?searchstring=" + encodedValue);
Source
Demo

Categories

Resources