Page 1 of 1
Javascript event crash on html() scripting command
Posted: 07 Mar 2018 08:20
by sysyfry
hi,
I try to execute a simple script with a click event, on the "html() scripting command" and I got an error message..
I use a simple JavaScript function as test :
Code: Select all
html("
<html>
<body>
<p id="demo" onclick="myFunction()">Click me to change my text color.</p>
<script>
function myFunction() {
document.getElementById("demo").style.color = "red";
}
</script>
</body>
</html>
");
the onclick event crash,
if executed on .html page it work, but if as try the same inside the html() script command of xyplorer it crash...
why it crash ? can we improve ?
for additional test i try without the onclick event :
Code: Select all
html("
<html>
<body>
<p id="demo">change my text color.</p>
<script>
document.getElementById("demo").style.color = "red";
</script>
</body>
</html>
");
this one work, so the JavaScript code work inside the html() scripting command of xyplorer, but not the click event ....
thanks
Re: Javascript event crash on html() scripting command
Posted: 07 Mar 2018 08:31
by admin
Does not crash here.
BTW, you have to double any quotes that are inside quotes:
Code: Select all
html("
<html>
<body>
<p id=""demo"" onclick=""myFunction()"">Click me to change my text color.</p>
<script>
function myFunction() {
document.getElementById(""demo"").style.color = ""red"";
}
</script>
</body>
</html>
");
Re: Javascript event crash on html() scripting command
Posted: 07 Mar 2018 08:35
by jupe
It works ok for me, no crash, can I ask what version of XY you are using?, what OS? what IE version?
edit: Also when you say "crash" if you are really just referring to a JS error popup, I would instead consider putting your html/js code in a Heredoc something like this:
Code: Select all
$html = <<<DOX
<html>
<body>
<p id="demo" onclick="myFunction()">Click me to change my text color.</p>
<script>
function myFunction() {
document.getElementById("demo").style.color = "red"; }
</script>
</body>
</html>
DOX;
html($html);
Re: Javascript event crash on html() scripting command
Posted: 08 Mar 2018 06:02
by sysyfry
jupe wrote:It works ok for me, no crash, can I ask what version of XY you are using?, what OS? what IE version?
edit: Also when you say "crash" if you are really just referring to a JS error popup, I would instead consider putting your html/js code in a Heredoc something like this:
Code: Select all
$html = <<<DOX
<html>
<body>
<p id="demo" onclick="myFunction()">Click me to change my text color.</p>
<script>
function myFunction() {
document.getElementById("demo").style.color = "red"; }
</script>
</body>
</html>
DOX;
html($html);
ok thank, that work

your answer is better.
i tried the double quote things, it don't work, same as before (but yes, i should check it, you right, it's an common error)
btw, the " <<<dox " command is much better and work perfectly, and you right was not an "crash" but an JS error popup
Re: Javascript event crash on html() scripting command
Posted: 08 Mar 2018 09:17
by admin
Use the word "crash" carefully... an error message is information, not a crash...

Re: Javascript event crash on html() scripting command
Posted: 09 Mar 2018 07:04
by sysyfry
jupe wrote:
$html = <<<DOX
<html>
<body>
</body>
</html>
DOX;
[/code]
thank you for your help,
but what is "<<<DOX DOX;" command ? what's mean ? where is the help/infos for that ?
and what is the programming language of the scripts in XYplorer ?
Re: Javascript event crash on html() scripting command
Posted: 09 Mar 2018 07:16
by jupe
jupe wrote:I would instead consider putting your html/js code in a Heredoc
you can paste the following into the XY address bar for more information if you are interested:
Code: Select all
::help "idh_scripting.htm#idh_scripting_heredoc";
XY scripting language is based on PHP but is it's own evolution, it is fully documented in the help file.
Re: Javascript event crash on html() scripting command
Posted: 10 Mar 2018 04:45
by sysyfry
jupe wrote: XY scripting language is based on PHP but is it's own evolution, it is fully documented in the help file.
Hooooo, I understand better now... yes look like PHP, but like you said it's an own evolution. Thank you