Kowa92 Posted March 22, 2012 Share Posted March 22, 2012 (edited) Hi all! And by the time I am creating a small web tool whose function is essentially that of a real online editor for those who want to experiment and quickly test the results of their written work with the basic programming languages such as HTML, CSS , XML, Java Script, etc. ...... This is the web tool made by me in php: w3schoolzz.altervista.org/webtools/tryit_editor.php I would ask you to be a dilemma to which I can not find solution ... I would like to know why when I write in the text box (to left) in a pure JS code (for example a button that once pressed gives a simple alert message) does not work in the preview window (right). Essentially, the web tool is very simple since it is based entirely on a form with its white page that captures the data written to the textarea via a simple request.The code goes something like this: Home (tryit_editor.php) PHP Code:--------------------------------------<? phpprint ('...<form name="tryited" action="myeditor.php" method="post" target="mypreview" onSubmit="return checkup();">... <textarea name="mytext" cols="77" rows="38"> HTML, JavaScript, CSS, etc. .. </ textarea>...</ form>...');?>--------------------------------------------- Secondary Page (myeditor.php) PHP Code:--------------------------------<? phpprint ($ _REQUEST ['myText']);?>-------------------------------------- I would also like to know a possible solution to this problem ... Thank you! Edited March 22, 2012 by Kowa92 Link to comment Share on other sites More sharing options...
Kowa92 Posted March 22, 2012 Author Share Posted March 22, 2012 I also noticed that if I open the browser's tool to inspect the inner iframe element, that the content between 2 different js script tag is empty if I type in the text window of any code in js. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 22, 2012 Share Posted March 22, 2012 What's an example string of code to paste that will show the problem? Link to comment Share on other sites More sharing options...
Kowa92 Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) What's an example string of code to paste that will show the problem?Any JS code. For example this: JS Code:------------------------------ <html><head><script type="text/javascript">function displayDate(){document.getElementById("demo").innerHTML=Date();}</script></head><body> <h1>My First Web Page</h1><p id="demo">This is a paragraph.</p> <button type="button" onclick="displayDate()">Display Date</button> </body></html>------------------- If we take a look at the page source of the iframe, we see that everything is correct and is exactly equal to what we write on the textarea. But if we open the tool inside the browser and inspect the iframe, it looks like this: ----------------------- <html><head><script type="text/javascript"></script></head><body> <h1>My First Web Page</h1><p id="demo">This is a paragraph.</p> <button type="button" onclick>Display Date</button> </body></html>----------------------- The onClick event and the content of script tags are empty and the script doesn't work!!!...Why? Edited March 22, 2012 by Kowa92 Link to comment Share on other sites More sharing options...
justsomeguy Posted March 22, 2012 Share Posted March 22, 2012 It's browser-specific, Opera will run the code but Chrome shows an error in the console that says it is refusing to run the code because the code was included in the request. Link to comment Share on other sites More sharing options...
Kowa92 Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) It's browser-specific, Opera will run the code but Chrome shows an error in the console that says it is refusing to run the code because the code was included in the request.Omg! And how can i fix it? Edited March 22, 2012 by Kowa92 Link to comment Share on other sites More sharing options...
justsomeguy Posted March 22, 2012 Share Posted March 22, 2012 Well, you can't change how the browser works. You can try to work around it, like doing a base64-encode on the data in Javascript before submitting it, and decoding it in PHP. Link to comment Share on other sites More sharing options...
Kowa92 Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) Well, you can't change how the browser works. You can try to work around it, like doing a base64-encode on the data in Javascript before submitting it, and decoding it in PHP.Can i use escape function (escape()) in js for encode the value from my textarea before send the form? Do you mean something like that as first of two steps? Edited March 22, 2012 by Kowa92 Link to comment Share on other sites More sharing options...
justsomeguy Posted March 22, 2012 Share Posted March 22, 2012 Something like that, but the browser will probably check for a basic escape. Using a base64-encode would be less likely to be checked. Link to comment Share on other sites More sharing options...
Kowa92 Posted March 31, 2012 Author Share Posted March 31, 2012 I've solved this problem without escaping/converting anything!However thanks for your help! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now