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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-24 12:11:11948browse

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 this 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




Untitled Document< ;/title> <br> <br>
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