1

list.html is not loading. Is this the correct way to load html file?

<div id="subscription"> </div>
<script>
    var i;
    for (i = 0; i < 5; i++) {
        document.getElementById("subscription").innerHTML = '<object type="text/html" data="list.html"></object>'
    }
</script>
1
  • you have 5 items in the list? Commented May 14, 2018 at 10:08

1 Answer 1

1

You cannot use:

<object type="text/html" data="list.html" ></object>

Best advice could be using <iframe>s:

<div id="subscription"> </div>
<script>
var i;
for (i = 0; i < 5; i++) {
  document.getElementById("subscription").innerHTML = '<iframe src="list.html"></iframe>';
}
</script>

But not sure why you need to loop it 5 times. You can just do:

<div id="subscription"> </div>
<script>
  document.getElementById("subscription").innerHTML = '<iframe src="list.html"></iframe>';
</script>
Sign up to request clarification or add additional context in comments.

8 Comments

Iist.html contains certain code that i need to loop
@vivekkumarchoubey Then you are doing it ultimately wrong. Can you explain in your question, what you are trying to do exactly? This looks like an XY problem - you are trying to do something, but you are doing it incorrectly assuming some wrong way to do and asking help for it.
@vivekkumarchoubey You can, but you need to use AJAX and also you need to run it on a HTTP server, and not using file:/// protocol.
I want to make dynamic web page where count can increase and decrease depending on number of users. Here i am using constant 5 just for example .
@vivekkumarchoubey In that case, you need to use a localhost using some HTTP server. Do you have any experience in backend programming - PHP seems to be a best start. What you are doing is called "including partials". :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.