-3

im curious to know if it's possible to remotely upload or reference a .html document from a file server through the javascript onload function. I have found out how to implement CSS & JS through the onload function but not quite the HTML. . i would be using this for a CMS that i use daily that limits my page customization..

Implementing JS example:

<img style="display: none;" src="IMAGE_NEEDED_FOR_ONLOAD_IMPLEMENTATION" onload="var body=document.getElementsByTagName('body')[0]; var script=document.createElement('script'); script.type='text/javascript'; script.src='JAVASCRIPT_FILE_GOES_HERE'; body.appendChild(script);">

Anybody happen to have a clue or have experience with this? I'm not looking to use an iFrame. Also, would this harm SEO?

Raylon
  • 53
  • 1
  • 8
  • 2
    You want to "remotely upload or reference a .html document from a file server through the javascript onload function"? Could you reword this so it's easier to understand what do you want to achieve? – Ma3x Sep 26 '16 at 20:45
  • i edited the original post. please see above :) – Raylon Sep 26 '16 at 20:51
  • You can use AJAX to get another HTML document, then assign to `element.innerHTML` to update the current page with it. – Barmar Sep 26 '16 at 21:02

1 Answers1

1

I believe what you want to do is to make an AJAX call to that HTML file. Please read Getting started with AJAX.

What you would need to do next is to add the result to your page, not with body.appendChild(script); this time but with the process described in this AJAX HTML injection answer.

EDIT: As for SEO, this used to be a clear "yes, it's problematic" as search engine crawlers did not have Javascript enabled but then last year Google started enabling JS in its crawlers, which is a good thing but also made the issue muddier. This article may be outdated but it runs through some of the uncertainties. I would say if you even think this could be an issue, you should probably look deeper into progressive enhancement. Or you can go ahead, implement in the client, measure the SEO impact after a while and assess whether it's worth changing the implementation too.

Community
  • 1
  • 1
shariffy
  • 26
  • 3