Jump to content

JS don't work?


Kowa92

Recommended Posts

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 by Kowa92
Link to comment
Share on other sites

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

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 by Kowa92
Link to comment
Share on other sites

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 by Kowa92
Link to comment
Share on other sites

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 by Kowa92
Link to comment
Share on other sites

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...