Javascript - use custom code from external source

cjzeus
2 Posts
cjzeus posted this 29 January 2023
Ask a Question

Hello, I'm new using nicepage, I have a custom javascript code that I want to run,
it works if I copy the entire code in the HTML element, but I want to reference the javascript file that is hosted in another public server, is this possible ?
Example, this works:

    <script type="text/javascript">  function msg(){ alert("Hello Javascript");} </script> 
   <script>msg();</script>

but the following code does not work, the message function is in a .js file on another server

<script type="text/javascript" src="http://customserver.com/public/script/jsfunctions.js"></script>
<script>msg();</script> 

the file jsfunctions.js has the code:

function msg(){ alert("Hello Javascript");  }  

The HTML element is in section of the body of the page.
when I see the source code of the page generated by nicepage, I see the reference to the src external localtion, if I click the scr URL, the browser displays the .js file contents. the .js file is not blocked.

Is there any addtional configuration for nicepage to load the javascript code from the external server?

We prefer to have the javascript code referenced from external file as the code might change and we only need to change it on the external file and no need to edit or modified the web site page already generated by nicepage

Thank you,

C.j.

Hello, I'm new using nicepage, I have a custom javascript code that I want to run, it works if I copy the entire code in the HTML element, but I want to reference the javascript file that is hosted in another public server, is this possible ? Example, this works: <script type="text/javascript"> function msg(){ alert("Hello Javascript");} </script> <script>msg();</script> but the following code does not work, the message function is in a .js file on another server <script type="text/javascript" src="http://customserver.com/public/script/jsfunctions.js"></script> <script>msg();</script> the file jsfunctions.js has the code: function msg(){ alert("Hello Javascript"); } The HTML element is in section of the body of the page. when I see the source code of the page generated by nicepage, I see the reference to the src external localtion, if I click the scr URL, the browser displays the .js file contents. the .js file is not blocked. Is there any addtional configuration for nicepage to load the javascript code from the external server? We prefer to have the javascript code referenced from external file as the code might change and we only need to change it on the external file and no need to edit or modified the web site page already generated by nicepage Thank you, C.j.
Vote to pay developers attention to this features or issue.
2 Replies
Order By: Standard | Newest
Support Team
Support Team posted this 30 January 2023

Hello,

There is no difference between adding custom js to the Nicepage page or any other static HTML page. If the custom js works ok on may static HTML pages, it should work with Nicepage pages too. Did you test your custom js on a simple static HTML page?

...................................................
Sincerely,
Olivia
Nicepage Support Team

Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1
Follow us on Facebook: http://facebook.com/nicepageapp

Hello, There is no difference between adding custom js to the Nicepage page or any other static HTML page. If the custom js works ok on may static HTML pages, it should work with Nicepage pages too. Did you test your custom js on a simple static HTML page? ................................................... Sincerely, Olivia Nicepage Support Team Please subscribe to our YouTube channel: http://youtube.com/nicepage?sub_confirmation=1 Follow us on Facebook: http://facebook.com/nicepageapp
cjzeus
2 Posts
cjzeus posted this 30 January 2023

Thank for the quick reply and thanks for confirming it should work.
Yes, I tested the custom js code on a simple static HTML page and it works on that static page.

I did another test, I moved the js code to another public repository where I know there are no traffic restrictions and the custom js code runs on the page built with nicepage, then it works now !!

Knowing it should work in nicepage and that it worked using the new location of the js file, I looked at the original source server, it is a machine hosted on AWS instance, it looks like there might be a firewall or security rule preventing nicepage to read the js code from that AWS machine.

I guess I would need to know what would be the nicepage IP at the time nicepage tries to read the custom js code and add it to the AWS security rules to allow it, but I don't know how to find that. In the meantime I will use the other public repository as it is working now.

Thanks again
C.

Thank for the quick reply and thanks for confirming it should work. Yes, I tested the custom js code on a simple static HTML page and it works on that static page. I did another test, I moved the js code to another public repository where I know there are no traffic restrictions and the custom js code runs on the page built with nicepage, then it works now !! Knowing it should work in nicepage and that it worked using the new location of the js file, I looked at the original source server, it is a machine hosted on AWS instance, it looks like there might be a firewall or security rule preventing nicepage to read the js code from that AWS machine. I guess I would need to know what would be the nicepage IP at the time nicepage tries to read the custom js code and add it to the AWS security rules to allow it, but I don't know how to find that. In the meantime I will use the other public repository as it is working now. Thanks again C.

Last edited 30 January 2023 by cjzeus

You must log in or register to leave comments