【问题标题】:React, how to open onclick function on a new tab?React,如何在新标签页上打开 onclick 功能?
【发布时间】:2021-05-20 04:52:53
【问题描述】:

在反应中,您如何重定向或在新标签中打开某些内容?我有一个按钮,单击时我想在新标签中打开它。现在它在当前选项卡中打开。这是按钮代码

<Button
                                  variant="contained"
                                  fullWidth={true}
                                  color="primary"
                                  disabled={loder === data._id ? true : false}
                                  onClick={() => viewRecording(data)}
                                >

这是那个函数

const viewRecording = (sessionData) => {
    setLoder(sessionData._id);
    const val = {
      meetingId: sessionData.meetingNo,
    };
    const onSuccess = (data) => {
      setLoder(null);
      console.log(data.recording_files);
      window.location.replace(data.recording_files[0].play_url);
    };
    const onError = () => {
      setLoder(null);
      openSnackbar("Recording not found for this session !!");
    };
    dispatch(ZoomMeetingRecording(val, onSuccess, onError));
  };

【问题讨论】:

标签: reactjs redirect routes onclick


【解决方案1】:

随便用

window.open(data.recording_files[0].play_url, '_blank'); 

代替

window.location.replace(data.recording_files[0].play_url);

【讨论】:

    猜你喜欢
    • 2017-06-03
    • 2013-06-21
    • 2021-11-24
    • 2015-05-26
    • 2016-09-17
    • 1970-01-01
    • 2019-09-09
    • 2012-03-11
    • 1970-01-01
    相关资源
    最近更新 更多