 |
 |
javascript: passing string with quotes
|
 |
|
 |
|
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status:
Offline
|
|
I'm trying to pass a string to a javascript function. The problem that I am having is that the string I am trying to pass contains single quotes. I've tried escaping them, but things still aren't working quite right. I don't get the entire string, but rather the first quote and the first word of the string I am trying to pass.
Here is an example of what I am trying to pass:
Code:
javascript:rewrite('title', '<br><br>javascript:encode('string1', 'string2')')
How would I go about passing the string containing the single quotes. I tried putting in double quotes, but it doesn't seem to like that.
|
|
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Dec 2002
Status:
Offline
|
|
javascript:rewrite("title", "java script:encode('string1', 'string2')")
That will work. If there's single quotes inside the actual strings use \' to display it as a '. If that doesn't work, supply more code so I can better view the problem. Good luck.
Travis
forté web design
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status:
Offline
|
|
The line of javascript code I need looks as follows:
Code:
{a href="javascript:showPrevious('December', '{a href="javascript:rewrite('title1', 'some lines of text')"}title1{/a}')"}
The problem that I am having is that I need to be able to include html tags and javascript code within a string parameter. The browser is reading the tags and it is screwing up my page. Is there any way to get around this?
|
|
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Dec 2002
Status:
Offline
|
|
Yes, but it's not pretty (at least the route I came up with):
Code:
<a href='javascript:showPrevious("December", "<a href=javascript:rewrite('title1' , 'some lines of text' )>title1</a>")'>
the link.</a>
The thing to note is in my post I am using HTML special character codes. In the code in of your page substitute the single-quotes around the month with &# 39; (minus the space) and the "inner" javascript link. If you want you can use &# 62; for the greater-than-sign and &# 60 for the less-than-sign. Make sure you don't put a space between java and script as well, IE6 doesn't recognize it that way (for me).
Travis
forté web design
//edit: grr the post keeps putting the space in the code between java and script, just make sure you're not doing it in the source code (you probably aren't..)
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status:
Offline
|
|
redjag,
That solution worked great, but there is still a problem somewhere. When I manually typed in a simple sentence for the second javascript's parameters (in the rewrite() function), everything worked how I wanted it to.
The problem now is that I am using php to pull in the contents of a file for each link. I can do that fine, but it seems as if javascript doesn't like to have certain characters in its parameters. Do you know what these characters are, so I can go about removing/replacing them? The parameter (that replaces 'some lines of text' in the rewrite() function) contains directory paths, image tags, link tags, and could possibly include other HTML tags, but those are most likely to appear. I've tried replacing <, >, ", and, ' with their respective HTML code, but I am still missing something. Do you know what other tags I need to remove? I'll try searching for a list of all characters that cause screwy javascript, so that I can hopefully prevent this from happening down the road.
Thanks.
|
|
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Dec 2002
Status:
Offline
|
|
The only thing I can think of that you didn't mention is a line break (I think its '\n'..?). If you're taking the link from a file, how are you doing this? You may be taking the line break at the end of the line, too. Other than that, I'm not really sure. If I think of anything I'll get back to you. If you'd like to post your php and a sample file I'll take a look at it. Good luck.
Travis
forté web design
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Nov 2001
Location: Washington, DC 20009
Status:
Offline
|
|
Thanks for the help guys. I actually have it working as I wanted it to.
|
|
Just my $.02 :-)
Ti Powerbook 1Ghz w/ Superdrive ......and lovin' it! :)
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|