Script to check if there are other scripts
When archiving web pages, dynamic content has to be treated differ开发者_运维问答ently. How do I detect whether a page uses any JavaScript?
This will end up in a browser extension, so it probably doesn't need to exclude itself from the findings.
Simply checking for <script>
tags should be fine.
if (document.querySelectorAll("script").length) {
//there are scripts on this page
}
You could scan the entire page for onclick
, etc handlers in HTML tags, but that would be slow for a big page.
That's actually relatively simple -- does it have any <script>
tags? Then it probably has dynamic content. Additionally, you may wish to check for <object>
tags as occasionally embedded objects will modify the page as well (though I suppose their presence should also make the page considered 'dynamic')
With javascript it ain't possible if javascript is turned off in your browser. You must make some browser check in your server-code.
精彩评论