Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Location
    San Francisco, CA, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Help with Favelet. All browsers work except IE!!!

    Okay here's the deal. I am working on this favelet (a snippet of JavaScript that can be pasted into the url line or setup as a clickable favorite to modify code on the page) that searches through all the links in all the frames and adds an onclick event to those whose href's begin with mailto:.

    The onclick event opens a new window and allows you to compose the message using your Yahoo email rather than an externally configured mail application.

    This works on all major browsers. It even works on Netscape 4 for gods sake and it won't work in IE. The only way it works in IE is if its part of a script tag that's actually embedded in the page to begin with. This makes the point of this script moot.

    Things I've tried are: Converting the code to an escaped string and basically doing javascript:eval(unescape('...')). But that doesn't work either.

    Here is the code as it would appear on in the favorite or url line:
    There should be no space between java and script:, but the post keeps inserting a space there. Please remove to test.


    javascript:{for(var f = 0, fct = frames.length; ((fct > 0) ? (f<fct) : (f<1)); f++){var doc=(fct>0)?frames[f].document:document,cnt=doc.links.length,lnk=doc.links;for(var i = 0; i < lnk.length; i++){if(lnk[i].href.indexOf("mailto:")!=-1){var qstr=lnk[i].href.toString().toLowerCase().split("?"),pairs=null,pair=null,j=0;lnk[i].to=qstr[0].split(":")[1];lnk[i].subj="";if(qstr.length){qstr=qstr[1]||"";pairs=qstr.split("&");for(j=0;j<pairs.length;j++){pair = pairs[j].split("=");if((pair[0]||"")=="subject")lnk[i].subj=pair[1]||"";}}lnk[i].onclick=function(){this.wind = window.open("http://us.f804.mail.yahoo.com/ym/Compose?login=1&to="+unescape(this.to)+"&subject="+unescape(this.subj),"Compose");return false;}}}}alert("All mailto: links have been modified");}


    and here it is again formatted for easy viewing:

    Code:
    for(var f = 0, fct = frames.length; ((fct > 0) ? (f<fct) : (f<1)); f++)
    {
      var doc=(fct>0)?frames[f].document:document,cnt=doc.links.length,lnk=doc.links;
      for(var i = 0; i < lnk.length; i++)
      {
        if(lnk[i].href.indexOf("mailto:")!=-1)
        {
          var qstr=lnk[i].href.toString().toLowerCase().split("?"),pairs=null,pair=null,j=0;
          lnk[i].to=qstr[0].split(":")[1];
          lnk[i].subj="";
    
          if(qstr.length)
          {
            qstr=qstr[1]||"";
            pairs=qstr.split("&");
    
            for(j=0;j<pairs.length;j++)
            {
              pair = pairs[j].split("=");
              if((pair[0]||"")=="subject")
                lnk[i].subj=pair[1]||"";
            }
          }
          
          lnk[i].onclick=function()
          {
            this.wind = window.open("http://us.f804.mail.yahoo.com/ym/Compose?login=1&to="+unescape(this.to)+"&subject="+unescape(this.subj),"Compose");
            return false;
          }
        }
      }
    }
    alert("All mailto: links have been modified");
    It seems to be breaking on the URL (as best as I can tell) at the for(j=0...) line. There is nothing wrong with the JavaScript as far as I can tell.

    For those of you who don't know the syntax var x = val || defaultVal; basically assigns val to x if val is a valid value and if not, undefined or null for example, defaultVal is assigned to x. This is part of the JavaScript reference language and is quite useful. I am explaining it because it is somewhat rare and not everybody knows about it.

    Please let me know as I am stumped on this.
    -nyteschayde
    Last edited by nyteschayde; 03-11-2004 at 10:17 PM.

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    IE has a limit on how long bookmarklets can be. as i recall, it's 256 characters, though it's been a while since i've messed with it, so i might be off on that. i figured the following might be a way around, but i don't remember if i ever tested it:

    javascript:newWin = window.open(); newWin.document.write('<html><script src="c:\\whereever\\local.js"><\/script><\/html>');void 0;

    i've been meaning to look into whether that works or not ( i don't see a reason it wouldn't, but i also don't see a reason why IE should chop its bookmarks after 256 characters, so who knows ) for a long time now. assuming it works, it offers a lot of advantages, including finally having the space to format a bookmarklet properly.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Location
    San Francisco, CA, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by joh6nn
    IE has a limit on how long bookmarklets can be. as i recall, it's 256 characters, though it's been a while since i've messed with it, so i might be off on that. i figured the following might be a way around, but i don't remember if i ever tested it:

    javascript:newWin = window.open(); newWin.document.write('<html><script src="c:\\whereever\\local.js"><\/script><\/html>');void 0;

    i've been meaning to look into whether that works or not ( i don't see a reason it wouldn't, but i also don't see a reason why IE should chop its bookmarks after 256 characters, so who knows ) for a long time now. assuming it works, it offers a lot of advantages, including finally having the space to format a bookmarklet properly.
    Unfortunately thats not going to work in this case. You'll notice that the url is to Yahoos site. There is infinitely more content on the resulting page than just a script.

    There is another way to load a script if you are using 5.0+ browsers (obviously this means NN6+ since there is no 5.0). You can do something like the following:

    Code:
    var s = document.createElement('script');
    // and either this
    with(s) {src = '..../script.js';}
    
    // or this
    s.setAttribute('src','..../script.js');
    
    // some people feel you should find the head
    // document.getElementByTagName('head')[0].appendChild(s);
    
    // but I think this works just fine
    document.body.appendChild(s);
    This seems to be the safest way to dynamically load a script in either a new window created by JavaScript or in the currently loaded window. I use another favelet that loads a console debugging tool in which I can execute JavaScript code and print to the window this way. The scripts are loaded from my site using this kind of dynamic script loading.

    About the URL limit I am pretty sure I have seen longer scripts on the URL line. In fact if I get rid of the for() loop I can add 15 more alert() statements and have it work fine. Of course I need to recurse the parameters so that wont work.

    If someone can figure this out or an alternate method that works for IE I would greatly appreciate it.

  • #4
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    as far as the length of bookmarklets, i'll defer to this, as the author seems to have done the work to back his claims up: http://www.squarefree.com/bookmarklets/limits.html

    maybe i've missed something, but i'm not sure i understand why it is that my suggestion wouldn't work. i'll admit that using the DOM's appendChild method is quite a bit more elegant than opening the script in a child window, but they should both have the same end effect; to bring an external script file into the executing domain. both an appended script, and a script running in a child window, should have access to a page's elements, just the same as a bookmarklet, or a javascript: url typed into the location bar.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #5
    New to the CF scene
    Join Date
    Mar 2004
    Location
    San Francisco, CA, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by joh6nn
    as far as the length of bookmarklets, i'll defer to this, as the author seems to have done the work to back his claims up: http://www.squarefree.com/bookmarklets/limits.html

    maybe i've missed something, but i'm not sure i understand why it is that my suggestion wouldn't work. i'll admit that using the DOM's appendChild method is quite a bit more elegant than opening the script in a child window, but they should both have the same end effect; to bring an external script file into the executing domain. both an appended script, and a script running in a child window, should have access to a page's elements, just the same as a bookmarklet, or a javascript: url typed into the location bar.
    Well I see what you're saying now. I was trying to avoid that but if I have no other choice then I could put the whole thing in a script on my site and invoke it from there. I was just looking for something a little more speedy than that.

    Checking out that site you recommended I could have a URL line that was up to 2000 characters according to the form on his site. IE seems to be rather picky with what favelets or bookmarklets it lets you use and which ones it doesnt.

    I would welcome another solution if someone can find one but otherwise I guess I will be stuck with the external script I wanted to avoid.



    nyteschayde

  • #6
    New to the CF scene
    Join Date
    Mar 2004
    Location
    San Francisco, CA, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok by trimming a lot and renaming variables into an unreadable mess and ... removing the support for framed pages I got it to work in IE.

    Here's the code

    Code:
    javascript&#58;{var l=document.links;for(var i = 0; i < l.length; i++){if(l[i].href.indexOf("mailto:")!=-1){var q=l[i].href.toLowerCase().split("?"),ps=null,p=null,j=0;l[i].to=q[0].split(":")[1];l[i].subj="";if(q.length){q=q[1]||"";ps=q.split("&");for(j=0;j<ps.length;j++){p = ps[j].split("=");if((p[0]||"")=="subject")l[i].subj=p[1]||"";}}l[i].onclick=function(){window.open("http://us.f804.mail.yahoo.com/ym/Compose?login=1&to="+this.to+"&subject="+this.subj);return false;}}}alert("Modified");}
    Thanks to the post below I was able to ammend this. Thanks.

    -nyteschayde
    Last edited by nyteschayde; 03-12-2004 at 08:22 PM.

  • #7
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by nyteschayde
    Once again this studpid post keeps separating the beginning java and script:
    That's why the "Use javascript&amp;#58; in place of javascript: in your post" tip was appended to this sticky: MUST READ- How to post a JavaScript question!
    hmm... ?

  • #8
    New to the CF scene
    Join Date
    Mar 2004
    Location
    San Francisco, CA, USA
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. I edited my post. I was getting frustrated and I should not have posted what I did.

    I appreciate the advice.

    -nyteschayde

  • #9
    Regular Coder
    Join Date
    Feb 2003
    Posts
    638
    Thanks
    0
    Thanked 0 Times in 0 Posts
    no problem...
    hmm... ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •