Javascript event crash on html() scripting command

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
Post Reply
sysyfry
Posts: 14
Joined: 07 Mar 2018 04:12

Javascript event crash on html() scripting command

Post 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

admin
Site Admin
Posts: 67271
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Javascript event crash on html() scripting command

Post 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>
   ");

jupe
Posts: 3570
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Javascript event crash on html() scripting command

Post 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);

sysyfry
Posts: 14
Joined: 07 Mar 2018 04:12

Re: Javascript event crash on html() scripting command

Post 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

admin
Site Admin
Posts: 67271
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Javascript event crash on html() scripting command

Post by admin »

Use the word "crash" carefully... an error message is information, not a crash... :)

sysyfry
Posts: 14
Joined: 07 Mar 2018 04:12

Re: Javascript event crash on html() scripting command

Post 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 ?

jupe
Posts: 3570
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Javascript event crash on html() scripting command

Post 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.

sysyfry
Posts: 14
Joined: 07 Mar 2018 04:12

Re: Javascript event crash on html() scripting command

Post 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

Post Reply