Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Please forgive if this is too simple. I am generating an html page to screen. Some of the lines of html are very long because I have an inline-javascript-mouseover pop-up message attached to the links. Something like this gets printed...

<a href='some.site.com/address' onmouseover='popup(long message here, describes contents of link)' onmouseout='hidepopup()'>nameoffile.pdf</a>

So when the line is very long, IE seems to wrap it thus creating an unterminated string error in javascript.

What causes this wrapping? Is there a fix/workaround? I am already using \n's where I can.
Help?
Thanks,
Cliff

Replies are listed 'Best First'.
Re: Dynamic HTML line too long
by dws (Chancellor) on Aug 23, 2002 at 18:11 UTC
    So when the line is very long, IE seems to wrap it thus creating an unterminated string error in javascript.

    How long is long? Line length doesn't matter much to IE. If you're getting unterminated strings, chances are that the problem is either in your code, or in the "long message" you're using in the onmouseover(). Perhaps that string has embedded quotes that aren't being properly escaped.

    Show us one of these broken long lines, and the code that generated it.

Re: Dynamic HTML line too long
by Anonymous Monk on Aug 23, 2002 at 18:15 UTC
    The odds are that it isn't the length per se, but rather that there is a character in the long lines which affects the parsing.

    In any case you can use HTML::Entities and call encode_entities($javascript, "\\W") to get a version of the string to stick in the URL which should be protected from both line-breaks and unexpected interpretation of input characters.

Re: Dynamic HTML line too long
by andreychek (Parson) on Aug 23, 2002 at 19:42 UTC
    Using HTML::Entities, as the above Annymous Monk mentioned, would be a good bet. However, if that doesn't work for you, you can break up long lines of text in JavaScript like so:
    var textmsg = "This is a long line of text that just " + "seems to keep on going and going and " + "is just particularly large."; <a href='some.site.com/address' onmouseover='popup(textmsg)' onmouseout='hidepopup()'> nameoffile.p +df</a>
    If the problem really is with the length of your line, breaking it up like so should fix that.

    As a side note, are you sure you want to pop up a message whenever somebody puts their mouse over a link? Many might find that somewhat undesirable.. perhaps having the file description as text under the link, or even using image rollovers might work.

    Browsers are beginning to offer functionality to block unrequested popup windows. I'm not sure whats considered "unrequested", but you may wish to test that out before your customers start complaining that they don't see any file descriptions :-)

    Good luck!
    -Eric

    --
    Lucy: "What happens if you practice the piano for 20 years and then end up not being rich and famous?"
    Schroeder: "The joy is in the playing."
    A reply falls below the community's threshold of quality. You may see it by logging in.
OT: DHTML unnecessary, use HTML "title" attribute
by BorgCopyeditor (Friar) on Aug 23, 2002 at 20:32 UTC

    Along the lines of "don't roll your own" and "don't reinvent the wheel," instead of Javascript, you could use the HTML attribute that is already defined to provide just the functionality you're trying to replicate: namely, the title attribute (and not alt, which is a whole 'nother beast, though Internet Explorer thinks otherwise). So,

    <a href="example.com" title="This is my title. There are many like it, but this one is mine. My title is my best friend.  It is my life.  I must master it as I master my life.">

    BCE
    --You'reYour culture will adapt to service our'sours.

Re: Dynamic HTML line too long
by Anonymous Monk on Aug 23, 2002 at 19:43 UTC
    Ah, urethra!
    Thank you for the enlightenment. I couldn't see the forest for the trees!
    I simply used
    $longmessage =~ s/\s/ /g;
    There must be some kind of endline character somewhere.
    And all is well!
    Thanks,
    again
    Cliff