/    Sign up×
Community /Pin to ProfileBookmark

Checking document with JavaScript

Hey there, guys,

I’ve got this issue: our server puts out some nonsense tags before the <html> tag and I’ve got to find a way to detect for which specific nonsense exists on the page. I know it’s a hack, but it’s necessary.

I found a means, by using document.body.parentNode.innerHTML which works on FireFox but I can’t find code that will work on both FireFox and IE.

This is what I came up with:

[CODE]<script type=”text/javascript”>
//This script corrects the layout of the page on the discrepancy checking page for post-shipping.

var pageContents = document.body.parentNode.innerHTML;

if ((pageContents.indexOf(“TemKey SP:10038 PN:2”) != -1) && (pageContents.indexOf(“TemKey SP:10038 PN:2”) < 100)) {
document.write(“XXSomethingXX”);
// alert(pageContents.indexOf(“TemKey SP:10038 PN:2”));
// alert(pageContents.slice(0,100));
}
</script>[/CODE]

As you can guess, I’m looking for “<!– TemKey SP:10039 PN:2” in the space before the <html> tag of the document.

This JavaScript exists in the footer of the page where the document.write needs to produce certain text.

The second part of the if-then statement (the part that asks if its less than 100) is so that on pages where TemKey isn’t high above the <html> tag, the Script won’t be ‘true’ given that it will detect that condition in itself at the bottom of the page.

Ideas?

Yours,
Sylvan (Dave)

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @Sylvan012 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...