关闭标签页时重定向?

时间:2019-01-08 05:52:52

标签: javascript

只要访客关闭标签,此代码就会向他们显示一条消息:

window.onbeforeunload = function() {
    return "Are you sure you want to leave?";
}

但是,这是我无法使用的代码:

window.onbeforeunload = function() {
    window.location.replace("http://www.example.com");
}

为什么当访问者关闭标签时,此代码不会将访问者重定向到example.com?有什么解决办法吗?

1 个答案:

答案 0 :(得分:0)

使用规范的 protected void onActivityResult(int requestCode, int resultCode, Intent data) { // handle result of CropImageActivity if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { CropImage.ActivityResult result = CropImage.getActivityResult(data); if (resultCode == RESULT_OK) { ((ImageView) findViewById(R.id.quick_start_cropped_image)).setImageURI(result.getUri()); Toast.makeText( this, "Cropping successful, Sample: " + result.getSampleSize(), Toast.LENGTH_LONG) .show(); textScratch = (TextView) this.findViewById(R.id.textView); detector = new TextRecognizer.Builder(this).build(); try{ InputStream stream = getContentResolver().openInputStream(data.getData()); Bitmap bitmap = BitmapFactory.decodeStream(stream); stream.close(); if (detector.isOperational() && null !=bitmap){ Frame frame = new Frame.Builder().setBitmap(bitmap).build(); SparseArray<TextBlock> textBlocks = detector.detect(frame); StringBuilder sb = new StringBuilder(); for (int i=0; i< textBlocks.size(); ++i){ TextBlock tb = textBlocks.get(i); sb.append(tb.getValue()); } if (textBlocks.size() ==0){ textScratch.setText("Scan failed"); }else{ textScratch.setText(sb.toString()); } }else{ textScratch.setText("Invalid image"); } }catch (Exception e){ textScratch.setText("Problem encored"); } }else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { Toast.makeText(this, "Cropping failed: " + result.getError(), Toast.LENGTH_LONG).show(); } } } 属性代替使用Msgbox "Hi there " & Environ("USERNAME"), vbInformation, "Greetings"

location.replace()