/    Sign up×
Community /Pin to ProfileBookmark

Can I use a tag to load a hidden HTML document?

I’m experimenting with some page re-format scripting, and I’ve been using loadXMLDoc() to load in an html document into a javascript variable. From there I can use it in my coded re-formatting experiments, keeping it hidden until the script completes.

loadXMLdoc() works, but maybe it is unnecessary overhead? I’ve been reading about the different uses of the html <link> tag, on the developer.mozilla.org site, and I’m beginning to wonder if there might be a way to do the same thing with a simple <link> tag. Is it possible to use <link> to “load” in the contents of an HTML document, and have it remain unseen but available to subsequent javascript code? If I included a line, maybe like this?…

<link rel=”import” type = “text/html” href=”/someFile.html”>

maybe the linktype (‘rel)’ has to be something else, but in any case even if it worked, how would I access the content? Can I put an ID attribute in a link tag, and then access it through a simple “document.getElementById()” call?

to post a comment

4 Comments(s)

Copy linkTweet thisAlerts:
@rootJan 20.2019 — If you are using an external file for CSS, then use the proper CSS tag and DEFER the loading so that the page loads, the script loads then the script works on the page.

Copy linkTweet thisAlerts:
@PeterPan_321authorJan 20.2019 — But I'm talking about loading a SEPARATE html file... separate from the existing HTML page. Thats why I've been using The loadXMLDoc() call. it works fine, but I'm always needing to support very old browsers, and loadXMLDoc() is pretty new. I know there's an older synchronous equivalent (document.load() I think?) but it is considered an error now. LINK, on the other hand, has been around since browsers began, so i was hoping to use it.

Are you saying to somehow place the HTML I want to load into a CSS file? I don't understand.
Copy linkTweet thisAlerts:
@rootJan 20.2019 — You don't need to load an entire document, when you use XML Http Requests to load up data, you load up the content that you need not an entire page.

If your file is going to be changing layout as in doing things that CSS is used for, then you are only crating a problem for you in as far a an over burden on the server.
Copy linkTweet thisAlerts:
@PeterPan_321authorJan 20.2019 — @root#1600200 No... I am going to be re-arranging the content using javascript, placing the altered contents into other page elements. I was trying to avoid delving deep into the code or application here, as I'll post that later. For now I was just wanting to see if it was possible to do it with a <LINK>. consider the following small piece of code...

[code=javascript]
var content="";

function loadXMLDoc(location) {


var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
content = this.responseText;
fillColumns();
}
};
try {
xhttp.open("GET", location, true);
xhttp.send();
}
catch(err) { alert("could not load from: " + location );}
}
[/code]


If I call this with a valid URL on my own server, I will have the entire HTML file in the variable called 'content'. All I wanted to know is whether I could do the same with a <LINK> tag somehow.

EDIT: By the way, just discovered that firefox allows XMLHttpRequest() to grab content from your own hard drive when testing pages at home. Seems a violation of security (no other browser allows it), but at least with FF, it IS a handy thing for testing the code and page.
×

Success!

Help @PeterPan_321 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...