Home >Web Front-end >HTML Tutorial >Collection Detect the code to display if there is content and comment if there is no content_html/css_WEB-ITnose

Collection Detect the code to display if there is content and comment if there is no content_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:11:11908browse

I have an article page. The user can choose XXX (which is a hyperlink code), and then the article page template will call this XXX. The code is:

<script type="text/javascript" src="XXX"></script>

But there is Many users cannot enter this XXX, which results in many article pages with empty JS links, so I would like to ask you how to detect this6550bf2572387aa6b38496e426285cd12cacc6d41bbb37262a98f745aa00fbf0 If there is no content, this line of code will be automatically commented.


Reply to discussion (solution)

If src is empty, the current page will be requested one more time


<head><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /><title>无标题文档</title></head><body><script type="text/javascript" src="1.js"></script><script type="text/javascript" src=""></script><script>	function $t(name, cot){		cot = cot || document;		return cot.getElementsByTagName(name);	}	var objs = $t('script');	var href = location.href;	for(var i=0,len = objs.length-1; i < len; i++){		if( objs[i].src == href){			document.body.removeChild(objs[i]);		}	}</script></body></html>




Please refer to

If src is empty, the current page will be requested one more time


HTML code


93f0f5c25f18dab9d176bd4f6de5d30e
7100fa45f28bb6991a414bf73227ab37
b2386ffb911b14667cb8f0f91ea547a7Untitled Document< ;/title>
9c3bca370b5104690d9ef395f2c5f8d1
6c04bd5ca3fcae76e30b72ad730ca86d
a075ef95efd9f29a924984042d3d921d Please tell me Next, what is that 1.js?

For testing, it means something is written in src.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn