问题描述:

I have the following example files:

index.html

<body>

<input type="file" name="image" onchange="handleUpload()">

<script>

function handleUpload() {

window.location = 'aa.html';

}

</script>

</body>

aa.html

<body>

success

</body>

After file upload I'm redirected to another page.

When I hit browser back button I get Uncaught ReferenceError: handleUpload is not defined at HTMLInputElement.onchange.

Can someone explain why is this happening? I understand why handleUpload is triggered but why it's undefined?

Update

My app is more complex. I use webpack to bundle my js files into a single file then I reference it in layout before closing body tag.

What i'm trying to do is a image preview when input file is filled. Everything works great but if I hit back button after the form was submitted I get that error.

I manage to avoid this problem by removing onchange from html and added a event listener in one of js file. This approach has a delay on opening the select file window.

网友答案:

Here is your Answer

    <input type="file" name="image" onchange="window.location='aa.html'">
相关阅读:
Top