Java script trying to see is working in browser?

I have a working Django project.

In my html page I have the following code:

{% block content}
<script>
 document.getElementById(“demo”).innerHTML=“Hello JavaScript”;
</script>

But nothing is displayed on the browser, only the what’s normally shown

Is their a way better to test to check and see if Java is working (I need an if statement, html not possible)

Can you advise please?

Thanks in advance.

1 Like

Use your browser’s developer tools to see what’s happening with JavaScript in the browser.

The console panel will show any error messages that might be displayed.

It’ll also allow you to examine the contents of the page.

Side note: It’s one set of three backticks, before and after the entire block of code. The lines of three backticks must be lines by themselves and not with any other text on the line. (And you need to use three backticks, not four.)

You have at least three different ways of doing this.

  • You can use the URL pathname property to get the current URL for the page and extract it from there.
  • You can use the Django json_script filter to render the value in a manner designed to be read by your code.
  • You can render the value as a data attribute on an appropriate element of the page and retrieve it from there.

Hi,

What would be the Java function / code to use to retrieve the URL_Path

from the top of the current active web page into a string variable?

or is it not possible?

Thanks in Advance.

It’s not a function, it’s an attribute of the current page, document.URL.

Example:
let my_url = document.URL;

It’s also available from the window.location.href attribute.

There are other attributes available at window.location that also give you different parts of the url.