How do I import HTML file to HTML Element?

Not favoritedFavorited Favorited 0 favourites
  • 3 posts
From the Asset Store
Convert multiple Excel files into JSON files and import them into construct3.
  • Hello, what's the best way to load the entirety of an HTML file from the Files folder into an HTML Element, as opposed to having the content pasted inside the object on the layout.

    Can't seem to find a direct way of doing it.

    Cheers!

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Perhaps you could use an iframe? That is the usual way for showing an entire HTML document with all its sub-resources.

    If you really only want to paste the content of a file in to a HTML element, then you can use AJAX to fetch the project file and insert it to the HTML element with the 'Set content' action. Note however if the HTML file is a full document and contains things like the <html>, <head> and <body> tags it probably won't work correctly as those elements normally only occur once in a page, and this would mean inserting a second set. So with this approach you should only use a fragment of content HTML in the HTML file.

  • Hey Ashley, thank you for the response!

    The idea is to avoid having the html file being stored locally on the instance, because the base HTML content isn't global to all instances (for instance, like a sprite's animation is), so making changes to one would force me to go and manually update the content of each single instance.

    Getting the html content directly from a file solves this issue. It also makes it easier to make quick edits to the content with code highlighting.

    The AJAX option worked (funnily enough I'm actually using the full document across multiple html elements without issues). It does have the limitation of only being able to access LastData, but there are workarounds.

    Even though the AJAX method does the job, having been relying heavily on the HTML Element object recently, I think it would be really useful to have an action that does this directly, mainly because it would allow us to take full advantage the built-in IDE when coding the html content.

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)