noroom
05-29-2005, 12:00 AM
i was browsing the forums for a while, and some people seem to be very experienced with Javascript. I only started playing with it last night, so I need you to help me a little...
if you put this in a webpage:
<A HREF='javascript:alert("w00t w00t pie!");'>Click or bookmark this</A>and then bookmark the link, you'll get a bookmarklet that shows an alert.
I wanted to add a button to my "Links" bar, that takes the address, extracts some strings from it, and sends me to another webpage, using some information extracted from the current location.
my first try looked like this:
if(window.location.href.indexOf("http://spaces.msn.com/members/")==0){
var loc=window.location.href
if(window.location.href.indexOf("/Blog/")>0){
var User=loc.substr(loc.indexOf("members/")+8,loc.indexOf("/Blog/",loc.indexOf("members/")+1)-loc.indexOf("members/")-8);
var Handle=loc.substr(loc.indexOf("Blog/")+5,loc.indexOf(".entry",loc.indexOf("Blog/")+1)-loc.indexOf("Blog/")-5);
window.location.href=("http://spaces.msn.com/members/"+User+"/PersonalSpace.aspx?_c11_BlogPart_handle="+Handle+"&_c11_BlogPart_blogpart=blogentry&_c11_BlogPart_frompart=myspace&_c=BlogPart&_c02_owner=1");
}else{
var User=loc.substr(loc.indexOf("members/")+8,loc.indexOf("/PersonalSpace.aspx",loc.indexOf("members/")+1)-loc.indexOf("members/")-8);
var Handle=loc.substr(loc.indexOf("handle=")+7,loc.indexOf("&",loc.indexOf("handle=")+1)-loc.indexOf("handle=")-7);
window.location.href=("http://spaces.msn.com/members/"+User+"/Blog/"+Handle+".entry");
}
}
function getbetween(sSource,sBefore,sAfter){
if((sSource.indexOf(sAfter,sSource.indexOf(sBefore)+1))>0){
return (sSource.substr((sSource.indexOf(sBefore)+sBefore.length),(sSource.indexOf(sAfter,sSource.indexOf(sB efore)+1)-sSource.indexOf(sBefore)-sBefore.length)));
} else {
return sSource.substr(sSource.indexOf(sBefore)+sBefore.length,sSource.length);
}
}
of course that didn't look too bookmarklet-friendly to me, so I converted it to this:
if(window.location.href.indexOf("http://spaces.msn.com/members/")==0){if(window.location.href.indexOf("/Blog/")>0){window.location.href=("http://spaces.msn.com/members/"+window.location.href.substr(window.location.href.indexOf("members/")+8,window.location.href.indexOf("/Blog/",window.location.href.indexOf("members/")+1)-window.location.href.indexOf("members/")-8)+"/PersonalSpace.aspx?_c11_BlogPart_handle="+window.location.href.substr(window.location.href.indexOf("Blog/")+5,window.location.href.indexOf(".entry",window.location.href.indexOf("Blog/")+1)-window.location.href.indexOf("Blog/")-5)+"&_c11_BlogPart_blogpart=blogentry&_c11_BlogPart_frompart=myspace&_c=BlogPart&_c02_owner=1");}else{window.location.href=("http://spaces.msn.com/members/"+window.location.href.substr(window.location.href.indexOf("members/")+8,window.location.href.indexOf("/PersonalSpace.aspx",window.location.href.indexOf("members/")+1)-window.location.href.indexOf("members/")-8)+"/Blog/"+window.location.href.substr(window.location.href.indexOf("handle=")+7,window.location.href.indexOf("&",window.location.href.indexOf("handle=")+1)-window.location.href.indexOf("handle=")-7)+".entry");}}
now, if i embed that into the HTML of my MSN Space (http://spaces.msn.com/members/noroom) (online blog) and then click on the link, it works (it takes me to the edit page for that post) but if i click it from within my bookmarks it doesn't work. I really don't want to add this link to every post I make, so bookmarklets are the only way to go.
Anyone can help me out here, please? I stayed up until 3 am last night trying to figure out why it won't do anything! :(
if you put this in a webpage:
<A HREF='javascript:alert("w00t w00t pie!");'>Click or bookmark this</A>and then bookmark the link, you'll get a bookmarklet that shows an alert.
I wanted to add a button to my "Links" bar, that takes the address, extracts some strings from it, and sends me to another webpage, using some information extracted from the current location.
my first try looked like this:
if(window.location.href.indexOf("http://spaces.msn.com/members/")==0){
var loc=window.location.href
if(window.location.href.indexOf("/Blog/")>0){
var User=loc.substr(loc.indexOf("members/")+8,loc.indexOf("/Blog/",loc.indexOf("members/")+1)-loc.indexOf("members/")-8);
var Handle=loc.substr(loc.indexOf("Blog/")+5,loc.indexOf(".entry",loc.indexOf("Blog/")+1)-loc.indexOf("Blog/")-5);
window.location.href=("http://spaces.msn.com/members/"+User+"/PersonalSpace.aspx?_c11_BlogPart_handle="+Handle+"&_c11_BlogPart_blogpart=blogentry&_c11_BlogPart_frompart=myspace&_c=BlogPart&_c02_owner=1");
}else{
var User=loc.substr(loc.indexOf("members/")+8,loc.indexOf("/PersonalSpace.aspx",loc.indexOf("members/")+1)-loc.indexOf("members/")-8);
var Handle=loc.substr(loc.indexOf("handle=")+7,loc.indexOf("&",loc.indexOf("handle=")+1)-loc.indexOf("handle=")-7);
window.location.href=("http://spaces.msn.com/members/"+User+"/Blog/"+Handle+".entry");
}
}
function getbetween(sSource,sBefore,sAfter){
if((sSource.indexOf(sAfter,sSource.indexOf(sBefore)+1))>0){
return (sSource.substr((sSource.indexOf(sBefore)+sBefore.length),(sSource.indexOf(sAfter,sSource.indexOf(sB efore)+1)-sSource.indexOf(sBefore)-sBefore.length)));
} else {
return sSource.substr(sSource.indexOf(sBefore)+sBefore.length,sSource.length);
}
}
of course that didn't look too bookmarklet-friendly to me, so I converted it to this:
if(window.location.href.indexOf("http://spaces.msn.com/members/")==0){if(window.location.href.indexOf("/Blog/")>0){window.location.href=("http://spaces.msn.com/members/"+window.location.href.substr(window.location.href.indexOf("members/")+8,window.location.href.indexOf("/Blog/",window.location.href.indexOf("members/")+1)-window.location.href.indexOf("members/")-8)+"/PersonalSpace.aspx?_c11_BlogPart_handle="+window.location.href.substr(window.location.href.indexOf("Blog/")+5,window.location.href.indexOf(".entry",window.location.href.indexOf("Blog/")+1)-window.location.href.indexOf("Blog/")-5)+"&_c11_BlogPart_blogpart=blogentry&_c11_BlogPart_frompart=myspace&_c=BlogPart&_c02_owner=1");}else{window.location.href=("http://spaces.msn.com/members/"+window.location.href.substr(window.location.href.indexOf("members/")+8,window.location.href.indexOf("/PersonalSpace.aspx",window.location.href.indexOf("members/")+1)-window.location.href.indexOf("members/")-8)+"/Blog/"+window.location.href.substr(window.location.href.indexOf("handle=")+7,window.location.href.indexOf("&",window.location.href.indexOf("handle=")+1)-window.location.href.indexOf("handle=")-7)+".entry");}}
now, if i embed that into the HTML of my MSN Space (http://spaces.msn.com/members/noroom) (online blog) and then click on the link, it works (it takes me to the edit page for that post) but if i click it from within my bookmarks it doesn't work. I really don't want to add this link to every post I make, so bookmarklets are the only way to go.
Anyone can help me out here, please? I stayed up until 3 am last night trying to figure out why it won't do anything! :(