Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28777
| Path | csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Stefan Weiss <krewecherl@gmail.com> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: How to pass a php variable to a javascript file (function)? |
| Date | Fri, 02 Oct 2015 12:14:22 +0200 |
| Organization | albasani.net |
| Lines | 51 |
| Message-ID | <mulldu$lli$1@news.albasani.net> (permalink) |
| References | <r6jPx.32747$nl4.14152@fx02.am4> <XnsA5276328DD4DEeejj99@194.109.6.166> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| X-Trace | news.albasani.net y87fbFXchowCoK5k37Ce0OTIJxdhO2z9BUUCC7oDOryyWCs3p807V0g+goUp4ReNG+SKjpjL21pERJBXvHudVQ== |
| NNTP-Posting-Date | Fri, 2 Oct 2015 10:14:22 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="brLRSEhBtKVYg8OGcTLXy89jxjSFW2qgexR0ggrp8KerFLi7yFq7sx32U0Fho+Sx2G0e5ZHDw6XaE4UH2zfkF3kk481DqcICuRUDKwCQOycZNoVxZhmGlFhrfTAW5lFG"; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
| In-Reply-To | <XnsA5276328DD4DEeejj99@194.109.6.166> |
| Cancel-Lock | sha1:21QRVWWGl52v7da6BXtUuUsxXs4= |
| Xref | csiph.com comp.lang.javascript:28777 |
Show key headers only | View raw
On 2015-10-02 09:44, Evertjan. wrote: > >> var some_string = <?php echo json_encode($sometext); ?>; > > This is totally errorprone, you need to enclose the litteral string in '-s > or "-s, ensuring that the ones used do not appear in the inner text. No, json_encode() already takes care of quoting and character escaping; adding extra quotes around the result would be a syntax error. That doesn't mean that json_encode() by itself is enough to safely escape strings as JavaScript literals. What if $sometext contains "</script>"? What actually has to be escaped - in addition to characters like quotes, newlines, etc - depends on which HTML version is used. For HTML5, the process and some pitfalls are described here: http://www.w3.org/TR/html5/scripting-1.html#restrictions-for-contents-of-script-elements Short version: | Note: The easiest and safest way to avoid the rather strange | restrictions described in this section is to always escape "<!--" as | "<\!--", "<script" as "<\script", and "</script" as "<\/script" […] > That variable some_string, being a clientside javascript varaiable on > another PAGE, was lost when leaving that page. > >> So in doSomething I want to be able to use this some_string created in >> php file. How can I do it? > > So you cannot. > > Why don't you create that string on the "index.html" PAGE, > that you probably will have to rename to "index.php". Thats one way to do it. Unfortunately, we don't know enough about OP's project to give any meaningful advice. For example, if we knew that `some_string` is relatively short, we could suggest passing it along to index.html in the query string. location.href = "index.html?s=" + encodeURIComponent(some_string); The script included from index.html could then read it back from the query string. In general, mixing dynamic and static files (PHP and plain HTML) like this tends to get messy. - stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 00:13 +0100
Re: How to pass a php variable to a javascript file (function)? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 09:44 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-02 12:14 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 11:43 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 11:58 +0100
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-02 13:38 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 12:53 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 13:46 +0100
Re: How to pass a php variable to a javascript file (function)? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-02 13:51 +0100
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-02 21:42 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-03 00:33 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 23:45 +0100
Re: How to pass a php variable to a javascript file (function)? Tim Streater <timstreater@greenbee.net> - 2015-10-02 23:55 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-03 00:02 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 23:49 +0100
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-02 21:37 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-03 00:34 +0200
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-03 04:35 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-05 01:11 +0200
Re: How to pass a php variable to a javascript file (function)? Tim Streater <timstreater@greenbee.net> - 2015-10-05 09:13 +0100
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-06 03:30 +0200
Re: How to pass a php variable to a javascript file (function)? Stefan Weiss <krewecherl@gmail.com> - 2015-10-10 00:27 +0200
Re: How to pass a php variable to a javascript file (function)? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-10-03 15:15 -0300
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-03 20:34 +0200
Re: How to pass a php variable to a javascript file (function)? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-10-03 15:59 -0300
Re: How to pass a php variable to a javascript file (function)? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-03 22:15 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 11:36 +0100
Re: How to pass a php variable to a javascript file (function)? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 16:34 +0200
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 16:00 +0100
Re: How to pass a php variable to a javascript file (function)? Tim Streater <timstreater@greenbee.net> - 2015-10-02 16:03 +0100
Re: How to pass a php variable to a javascript file (function)? JiiPee <no@notvalid.com> - 2015-10-02 17:08 +0100
solution, thanks, seems like one suggestion lead to a solution JiiPee <no@notvalid.com> - 2015-10-02 17:07 +0100
Re: solution, thanks, seems like one suggestion lead to a solution "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2015-10-02 20:29 +0200
csiph-web