I don't know much about javascript (only done JAVA) but that havent keept me from doing a hack on some javascript code I found (from Google Bookmarks).
Here is my case: I'm creating a bookmark in my browser that contains a javascript instead of a URL link. When I press the bookmark I want it to open a new window with the same url but with some extra info. So say Im on https://www.abcde.com/KnowYourABC and I press the bookmark, then it should open a window with the link: https://www.abcde.com.DoYou/KnowYourABC - so ".DoYou" have been inserted just before the 3th "/"
I have the following script:
javascript:(function(){
var a=window, b=document, c=encodeURIComponent,
url = b.location,
d = a.open(url, "bkmk_popup", "left="+
((a.screenX||a.screenLeft)+50)+",top="+
((a.screenY||a.screenTop)+50)+
",height=600px, width=1200px, resizable=1, alwaysRaised=1");
a.setTimeout(function(){d.focus()},300)
})();
So far it opens a window with the same url. But I can't seem to split the url at the 3th "/". Have tried to get the index of the backslash in order to split the url and insert ".DoYou"
i = url.indexOf("//",9)
but then the window will not open. Please help me out!
SOLUTION
javascript:( function(){
var a=window;
b=document;
c=encodeURIComponent;
url = b.location;
var parts = window.location.href.split("/");
parts[2] += ".DoYou";
var newurl = parts.join("/");
a.open(newurl, "bkmk_popup","left="+((a.screenX||a.screenLeft)+50)+",top="+((a.screenY||a.screenTop)+50)+",height=600px,width=1200px,resizable=1,alwaysRaised=1"); a.setTimeout(function(){d.focus()},300);
})();
/is a regular slash. `\` is a backslash./only needs to be escaped in regexpes, where is becomes\/. In strings/is sufficient (it doesn't clash with anything).