Reputation: 3
The issue is I'm trying to grab part of a URL and place it within a new one, then load the new URL. I've done this before, but for this situation, it's taking the new URL and adding it after the already loaded one. Here is my code (as plain Javascript, not as bookmarklet):
function(){
var replaceLink = window.location.href;
var link = replaceLink.split('imgur.com/');
window.location.href = 'filmot.org/' + link[1];
}
What it's returning is imgur.com/filmot.org/[id]. Thanks.
Upvotes: 0
Views: 317
Reputation: 6904
It thinks "filmot.org/" is a relative link. This means that it will be relative to whatever website this code is run on. If you use this on imgur.com, then your window.location.href
will navigate to imgur.com/filmot.org/whatever.
You need to specify it as a URL with a protocol prefix ("http://filmot.org/") or a protocol-agnostic prefix ("//filmot.org/").
Upvotes: 2