JavaScript实现window.open最大化技巧

需积分: 6 1 下载量 44 浏览量 更新于2024-09-11 收藏 15KB DOCX 举报
"该资源主要讨论如何使用JavaScript的window.open函数来实现窗口的最大化操作。提供的方法包括在父页面调用open_fullScreen函数打开新窗口并设置初始尺寸,以及在子页面通过setTimeout调整窗口位置和大小以达到最大化效果。此外,还提到了其他网友尝试但效果不佳的解决方案作为参考。" 在网页开发中,有时需要使用JavaScript来控制窗口的行为,例如弹出一个新窗口并使其最大化。`window.open` 是JavaScript中的一个内置函数,用于打开新的浏览器窗口或替换现有窗口。在给定的代码示例中,`window.open` 函数用于创建一个新的窗口,并通过传递参数来设置其初始尺寸、状态栏、可调整大小、工具栏、菜单栏和滚动条等属性。 `open_fullScreen` 函数首先定义了一个生成随机验证码的辅助函数`createCode`,这在实际操作中并不直接相关,但可以用于生成唯一的窗口名称,避免与已存在的窗口重叠。然后,`open_fullScreen` 使用`window.screen.width` 和 `window.screen.height` 获取用户的屏幕宽度和高度,以此来创建一个与屏幕大小相同的窗口,这看起来像是最大化了窗口,但实际上这只是设置了一个全屏大小的窗口,而不是真正的最大化。 真正实现最大化的关键在于子页面中的代码。利用jQuery库,子页面加载完成后,通过`setTimeout` 设置一个延迟执行的函数,`top.moveTo(0,0)` 将窗口移动到屏幕的左上角(坐标0,0),`top.resizeTo(screen.availWidth,screen.availHeight)` 则将窗口大小调整为可用屏幕的宽度和高度,即用户屏幕减去任务栏或其他不可用区域的大小,这样就实现了窗口的实际最大化。 然而,需要注意的是,这种方法可能受到浏览器的安全策略和用户设置的影响,有些浏览器可能会阻止脚本自动调整窗口大小或位置。此外,由于跨域安全限制,只有当子窗口和父窗口同源时,才能在子窗口中通过`top`对象访问和操作父窗口。 另外,描述中提到了其他网友提供的解决方案,但未明确指出具体方法,通常这些方法可能包括使用特定的浏览器特性或者尝试通过CSS和JavaScript模拟最大化效果,但由于兼容性和权限问题,效果可能不尽人意。 实现JavaScript窗口最大化的最佳实践应该是尽可能地尊重用户的浏览体验和设置,避免强制最大化窗口,而是允许用户自行决定窗口的大小和位置。如果确实需要全屏展示内容,可以考虑使用HTML5的全屏API,但这通常适用于特定的交互场景,如游戏或视频播放,而不是普通的弹出窗口。

def unzip_infer_data(src_path,target_path): ''' 解压预测数据集 ''' if(not os.path.isdir(target_path)): z = zipfile.ZipFile(src_path, 'r') z.extractall(path=target_path) z.close() def load_image(img_path): ''' 预测图片预处理 ''' img = Image.open(img_path) if img.mode != 'RGB': img = img.convert('RGB') img = img.resize((224, 224), Image.BILINEAR) img = np.array(img).astype('float32') img = img.transpose((2, 0, 1)) # HWC to CHW img = img/255 # 像素值归一化 return img infer_src_path = './archive_test.zip' infer_dst_path = './archive_test' unzip_infer_data(infer_src_path,infer_dst_path) para_state_dict = paddle.load("MyDNN") model = MyDNN() model.set_state_dict(para_state_dict) #加载模型参数 model.eval() #验证模式 #展示预测图片 infer_path='./archive_test/alexandrite_18.jpg' img = Image.open(infer_path) plt.imshow(img) #根据数组绘制图像 plt.show() #显示图像 #对预测图片进行预处理 infer_imgs = [] infer_imgs.append(load_image(infer_path)) infer_imgs = np.array(infer_imgs) label_dic = train_parameters['label_dict'] for i in range(len(infer_imgs)): data = infer_imgs[i] dy_x_data = np.array(data).astype('float32') dy_x_data=dy_x_data[np.newaxis,:, : ,:] img = paddle.to_tensor (dy_x_data) out = model(img) lab = np.argmax(out.numpy()) #argmax():返回最大数的索引 print("第{}个样本,被预测为:{},真实标签为:{}".format(i+1,label_dic[str(lab)],infer_path.split('/')[-1].split("_")[0])) print("结束")根据这一段代码续写一段利用这个模型进行宝石预测的GUI界面

2023-05-25 上传

下面代码什么作用class MainWindow(QMainWindow, Ui_mainWindow): def init(self, parent=None): super(MainWindow, self).init(parent) self.setupUi(self) self.m_flag = False # style 1: window can be stretched # self.setWindowFlags(Qt.CustomizeWindowHint | Qt.WindowStaysOnTopHint) # style 2: window can not be stretched self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint) # self.setWindowOpacity(0.85) # Transparency of window self.minButton.clicked.connect(self.showMinimized) self.maxButton.clicked.connect(self.max_or_restore) # show Maximized window # self.maxButton.animateClick(10) self.closeButton.clicked.connect(self.close) self.qtimer = QTimer(self) self.qtimer.setSingleShot(True) self.qtimer.timeout.connect(lambda: self.statistic_label.clear()) # search models automatically 自动搜索模型 self.comboBox.clear() self.pt_list = os.listdir('./pt') self.pt_list = [file for file in self.pt_list if file.endswith('.pt')] self.pt_list.sort(key=lambda x: os.path.getsize('./pt/'+x)) self.comboBox.clear() self.comboBox.addItems(self.pt_list) self.qtimer_search = QTimer(self) self.qtimer_search.timeout.connect(lambda: self.search_pt()) self.qtimer_search.start(2000) # yolov5 thread self.det_thread = DetThread() self.model_type = self.comboBox.currentText() self.det_thread.weights = "./pt/%s" % self.model_type self.det_thread.source = '0' self.det_thread.percent_length = self.progressBar.maximum() self.det_thread.send_raw.connect(lambda x: self.show_image(x, self.raw_video)) self.det_thread.send_img.connect(lambda x: self.show_image(x, self.out_video)) self.det_thread.send_statistic.connect(self.show_statistic) self.det_thread.send_msg.connect(lambda x: self.show_msg(x)) self.det_thread.send_percent.connect(lambda x: self.progressBar.setValue(x)) self.det_thread.send_fps.connect(lambda x: self.fps_label.setText(x)) self.fileButton.clicked.connect(self.open_file) self.cameraButton.clicked.connect(self.chose_cam) self.rtspButton.clicked.connect(self.chose_rtsp) self.runButton.clicked.connect(self.run_or_continue) self.stopButton.clicked.connect(self.stop) self.comboBox.currentTextChanged.connect(self.change_model) self.confSpinBox.valueChanged.connect(lambda x: self.change_val(x, 'confSpinBox')) self.confSlider.valueChanged.connect(lambda x: self.change_val(x, 'confSlider')) self.iouSpinBox.valueChanged.connect(lambda x: self.change_val(x, 'iouSpinBox')) self.iouSlider.valueChanged.connect(lambda x: self.change_val(x, 'iouSlider')) self.rateSpinBox.valueChanged.connect(lambda x: self.change_val(x, 'rateSpinBox')) self.rateSlider.valueChanged.connect(lambda x: self.change_val(x, 'rateSlider')) self.checkBox.clicked.connect(self.checkrate) self.saveCheckBox.clicked.connect(self.is_save) self.load_setting()

2023-06-03 上传