Home Web Front-end JS Tutorial Introduction to BOM browser mode and window object

Introduction to BOM browser mode and window object

Oct 11, 2017 am 09:43 AM
firefox webkit window

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>
BOM浏览器模式和window对象学习
</title>
  <!--
   BOM浏览器模式(Browser Object Mode)这是一种理想的模式,如果每个浏览器开发商都按照这种方式来开发,
   就会提高开发效率,使互联网朝着健康的方向发展。
  具体的实现是window对象
  
 
1.框体方法
:alert();警告,无返回值
     confirm();确认,有返回值,确定返回true,取消返回false
     prompt();提示,有返回值,确定返回当前输入的值,取消返回null
   
2.定时执行和间隔执行
:
    setTimeOut(code expresion,time),指定时间后开辟线程执行指定的函数,返回线程id
    setInterval(code expresion,time),指定时间后开辟线程执行指定的函数,返回id
    ClearInterval(id),关闭指定的interval开启的线程
    ClearTimeOut(id),关闭指定的Timeout开启的线程
  
 3.子页面
    open()使用此方法可以打开当前页面的子页面,使用以下属性可以设置子页面窗口的大小和其他属性
    //height width top left 
    //toolbar=yes; menubar=yes;scrollbars=no;resizable=no;location=no;status=no; 
    
    close(),在open()打开的子页面中调用此方法
    
   
 重要属性
    opener
,使用opener可以调用父页面的函数 window.opener.函数名();
  -->
  <script type="text/javascript">
  //window方法举例
   //1.警告框
   function testAlert(){
    window.alert("我是警告框");
   }
   //2.确认框
   function testConfirm(){
    var flag=window.confirm("你要卸载我吗?");
    window.alert(flag);
   }
   //3.提示框
   function testPrompt(){
    var str=window.prompt("请输入昵称:","例如:李白");
    window.alert(str);
   }
   /*--------------------------------------------------------------------------*/
   //定时执行
   var tid;
   function testSetTimeOut(){
    tid=window.setTimeout(function(){
     alert("定时执行");
    },3000);
   }
   //间隔执行
   var id;
   function testInterval(){
    id=window.setInterval(function(){
     alert("间隔执行");
    },2000);
   }
   //关闭间隔执行
   function testClearInterval(){
    window.clearInterval(id);
   }
   //关闭定时执行
   function testClearTimeOut(){
    window.clearTimeout(tid);
   }
/*----------------------------------------------------------------------------------------*/
   function testOpen1(){
    window.open("http://www.baidu.com");//使用open打开网络资源
    
   }
   function testOpen2(){
    window.open("sun.html");//使用open打开本地资源
    
   }
   //属性
   function testOpener(){
    alert("我是Opener");
   }
  </script>
 </head>
 <body>
  <input type="button" id="" value="测试windowAlert" onclick="testAlert();"/>
  <input type="button" id="" value="测试Confirm" onclick="testConfirm();"/>
  <input type="button" id="" value="测试prompt" onclick="testPrompt();" />
  <hr />
  <input type="button" id="" value="测试setTimeOut" onclick="testSetTimeOut();"/>
  <input type="button" id="" value="测试interval" onclick="testInterval();"/>
  <input type="button" id="" value="测试关闭clearInterval" onclick="testClearInterval();"/>
  <input type="button" id="" value="测试关闭TimeOut" onclick="testClearTimeOut();"/>
  <hr />
  <input type="button" id="" value="测试子页面" onclick="testOpen1();"/>
  <input type="button" id="" value="测试打开本地资源" onclick="testOpen2();"/>
 </body>
</html>
Copy after login

The above is the detailed content of Introduction to BOM browser mode and window object. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to remove Firefox Snap in Ubuntu Linux? How to remove Firefox Snap in Ubuntu Linux? Feb 21, 2024 pm 07:00 PM

To remove FirefoxSnap in Ubuntu Linux, you can follow these steps: Open a terminal and log in to your Ubuntu system as administrator. Run the following command to uninstall FirefoxSnap: sudosnapremovefirefox You will be prompted for your administrator password. Enter your password and press Enter to confirm. Wait for command execution to complete. Once completed, FirefoxSnap will be completely removed. Note that this will remove versions of Firefox installed via the Snap package manager. If you installed another version of Firefox through other means (such as the APT package manager), you will not be affected. Go through the above steps

Can mozilla firefox be uninstalled? Can mozilla firefox be uninstalled? Mar 15, 2023 pm 04:40 PM

Mozilla Firefox can be uninstalled; Firefox is a third-party browser and can be uninstalled if it is not needed. Uninstallation method: 1. In the Start menu, click "Windwos System" - "Control Panel"; 2. In the "Control Panel" interface, click "Programs and Features"; 3. In the new interface, find and double-click Firefox Browser icon; 4. In the uninstall pop-up window, click "Next"; 5. Click "Uninstall".

Firefox 113 new features: support for AV1 animations, enhanced password generator and picture-in-picture features Firefox 113 new features: support for AV1 animations, enhanced password generator and picture-in-picture features Mar 05, 2024 pm 05:20 PM

According to recent news, while Mozilla released the stable version of Firefox 112, it also announced that the next major version, Firefox 113, has entered the Beta channel and supports AV1 animations, enhanced password generator and picture-in-picture features. The main new functions/features of Firefox 113 are as follows: Support for AV1 format animated images (AVIS); Enhance the security of the password generator by introducing special characters; Enhance the picture-in-picture function, support rewind, display video time, and enable full screen more easily Mode provides official DEB installation files for Debian and Ubuntu distributions. Updated bookmark import feature, icons for imported bookmarks are supported by default. Hardware accelerated AV1 video decoding is enabled by default on supported hardware using w

How to use Mozilla Firefox in Scrapy to solve the problem of scanning QR code to log in? How to use Mozilla Firefox in Scrapy to solve the problem of scanning QR code to log in? Jun 22, 2023 pm 09:50 PM

For crawlers to crawl websites that require login, verification code or scan code login is a very troublesome problem. Scrapy is a very easy-to-use crawler framework in Python, but when processing verification codes or scanning QR codes to log in, some special measures need to be taken. As a common browser, Mozilla Firefox provides a solution that can help us solve this problem. The core module of Scrapy is twisted, which only supports asynchronous requests, but some websites require the use of cookies and

Apple releases update to fix WebKit vulnerability and excessive power consumption in MacBook Apple releases update to fix WebKit vulnerability and excessive power consumption in MacBook Apr 15, 2023 am 10:49 AM

Apple has released updates for iPhone, iPad, Mac and Apple Watch. Although the updates for each device are small, they address WebKit vulnerabilities. The company also assured that it has fixed a bug that caused MacBook laptops to unexpectedly drain their batteries. Apple iOS and iPadOS 15.3.1 are minor updates. It doesn't actually contain any major features. However, it is useful for people using braille displays. Additionally, the update resolves an arbitrary code execution vulnerability. The update notes for iOS 15.3.1 mention: iOS 15.3.1 provides important security updates for your iPhone and fixes

Ubuntu 23.10 will run Firefox in native Wayland mode by default Ubuntu 23.10 will run Firefox in native Wayland mode by default Feb 29, 2024 am 10:10 AM

Canonical recently announced that in the upcoming Ubuntu 23.10, Firefox Snap has been configured to run in Wayland mode by default. Note: Ubuntu currently has the Wayland session by default, and Firefox can also work normally. However, currently FirefoxSnap actually runs in XWayland compatibility mode, rather than the strict native Wayland mode. Canonical announced that it will run the Firefox browser in Wayland mode by default, so that problems such as interface blur and scaling distortion will not occur on HiDPI displays, and it will support touch gestures such as dragging and pinching. As mentioned above, Ubunt

How to solve Windows worm virus How to solve Windows worm virus May 17, 2023 pm 07:22 PM

0x00 Preface The worm is a very old computer virus. It is a self-contained program (or a set of programs) that usually spreads through the network. Every time it invades a new computer, it is on this computer. Makes a copy of itself and automatically executes its own program. Common worms: Panda Burning Incense Virus, Shock Wave/Shock Wave Virus, Conficker Virus, etc. 0x01 Emergency Scenario One morning, the administrator found at the egress firewall that the internal network server continued to initiate active connections to overseas IPs. The internal network environment was unable to connect to the external network, and there was no way to figure it out. 0x02 event analyzes the server's intranet IP seen on the egress firewall. First, disconnect the virus-infected host from the intranet, then log in to the server, open D-shield_web scan and check

Europe allows Apple to relax browser restrictions: Non-WebKit engines can be selected, Chrome can be used as the default browser Europe allows Apple to relax browser restrictions: Non-WebKit engines can be selected, Chrome can be used as the default browser Jan 26, 2024 am 10:42 AM

According to news on January 26, after iPhone users in Europe upgrade to the iOS17.4Beta1 update, they will see a new window after opening the Safari browser, which supports changing the default browser. Users in Europe can set up non-Safari browsers including Firefox, Opera, Chrome, Brave and Microsoft Edge according to their own preferences. Browser apps can now also use browser engines other than WebKit, including browser apps and in-app browsing experiences. Apple previously required that all browsers on iOS, including common browsers such as Chrome and Firefox, must use the WebKit engine.

See all articles