You need add href property and check indexOf
instead of contains
(您需要添加href属性并检查indexOf
而不是contains
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { if (window.location.href.indexOf("franky") > -1) { alert("your url contains the name franky"); } }); </script>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…