Welcome to DU! The truly grassroots left-of-center political community where regular people, not algorithms, drive the discussions and set the standards. Join the community: Create a free account Support DU (and get rid of ads!): Become a Star Member Latest Breaking News Editorials & Other Articles General Discussion The DU Lounge All Forums Issue Forums Culture Forums Alliance Forums Region Forums Support Forums Help & Search

Jesus Malverde

(10,274 posts)
Sun Jan 12, 2014, 10:11 PM Jan 2014

Javascript pros, code help needed.....

Last edited Mon Jan 13, 2014, 12:08 AM - Edit history (1)

I have an applescript that uses javascript to take the current selected text in safari, opens a new window, goes to the GD new post form and sets the title and body.

My problem is, if my selected text contains a quote, than the javascript will fail. How do I escape the quotes in javascript.

I'm using the following javascript. Keep in mind it's written to be fired by applescript.

do JavaScript &quot ''+getSelection())" in document 1)

do JavaScript "
document.forms['form2']['title'].value = '" & thename & "' ;
document.forms['form2']['message-text'].value ='" & newselectedText & pageURI & "' ;" in doc

How do I tell javascript to treat +getSelection like string and not text...

Peace and TIA.

If any high post count peeps want the complete applescript... send me a pm.

8 replies = new reply since forum marked as read
Highlight: NoneDon't highlight anything 5 newestHighlight 5 most recent replies
Javascript pros, code help needed..... (Original Post) Jesus Malverde Jan 2014 OP
Off the top of my head... hootinholler Jan 2014 #1
Thanks for your help on this one. Jesus Malverde Jan 2014 #2
The first thing to remember about javascript is hootinholler Jan 2014 #3
Message auto-removed Name removed Oct 2020 #6
Message auto-removed Name removed Jun 2020 #4
Message auto-removed Name removed Sep 2020 #5
Message auto-removed Name removed Jul 2021 #7
Thank you radhashetty Jun 2023 #8

hootinholler

(26,451 posts)
1. Off the top of my head...
Mon Jan 13, 2014, 03:56 PM
Jan 2014

You can't tell javascript to behave differently. There is no DWIM statement

I would try something like getSelection().replace(/"/g,""&quot ; Which should replace all " with the entity "

Admittedly, I would have to fuss with it to get it right, quote chars are tricky.

On Edit, quotes are tricky and du accepts the XML entity quot and translates it into a quote, so in the above line, the " inside the "" should be the entity & quot ; without the spaces.

Jesus Malverde

(10,274 posts)
2. Thanks for your help on this one.
Wed Jan 22, 2014, 02:31 PM
Jan 2014

I think my original sense it was a quote bug was wrong. Thanks again for your help, I wish I knew js better.

I like jquery a lot, mostly as a google copy paste coder.

hootinholler

(26,451 posts)
3. The first thing to remember about javascript is
Wed Jan 22, 2014, 03:36 PM
Jan 2014

It's a huge kludge!

The second thing to remember is it's an even bigger kludge.

The third thing to remember is it ain't Java.

Might I recommend a short book? http://shop.oreilly.com/product/9780596517748.do Javascript, The Good Parts.

Also a video, the first 5 minutes are well worth watching even if you don't care for the subject.

Response to Jesus Malverde (Reply #2)

Response to Jesus Malverde (Original post)

Response to Jesus Malverde (Original post)

Response to Jesus Malverde (Original post)

Kick in to the DU tip jar?

This week we're running a special pop-up mini fund drive. From Monday through Friday we're going ad-free for all registered members, and we're asking you to kick in to the DU tip jar to support the site and keep us financially healthy.

As a bonus, making a contribution will allow you to leave kudos for another DU member, and at the end of the week we'll recognize the DUers who you think make this community great.

Tell me more...

Latest Discussions»Retired Forums»Website, DB, & Software Developers»Javascript pros, code hel...