简体   繁体   中英

Why isn't this script working?

I put this into Notepad and saved as an htm. However, when I open it in IE, it just says the text without the <HEAD> and </HEAD> . I have tried encoding it as Unicode, UTF-8, Unicode big Endian, and ANSI.:

<HEAD>
var ifbumper=0
if (ifbumper=0)
  {
  window.location='/bumper?url=whatever'
  }
</HEAD>

You're writing JavaScript code, you need to put it inside of <script> tags. You also need to use == instead of = to compare values, and it's a good idea to put a ; following a line of code.

<HTML>
<HEAD>
<SCRIPT>
    var ifbumper=0;
    if (ifbumper==0)
    {
        window.location='/bumper?url=whatever';
    }
</SCRIPT>
</HEAD>

You need to wrap JavaScript code inside <script> tags like this:

<head>
    <script type="text/javascript">
        var ifbumper = 0;
        if (ifbumper == 0){
            window.location='/bumper?url=whatever';
        }
     </script>
</head>

The equality operator is ==, not just =. Your if should be a if (ifbumper == 0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM