Home Backend Development PHP Tutorial How to create html browser export and download using JS

How to create html browser export and download using JS

Mar 17, 2018 am 10:54 AM

This article mainly shares with you the method of creating HTML browser export download with JS. It mainly uses the download attribute and Blob of html5. I hope it can help you.

URL.createObjectURL

The URL.createObjectURL() method will create a URL pointing to the parameter object based on the passed in parameters. The life of this URL only exists in the document in which it is created. . The new object URL points to the executed File object or Blob object.

objectURL = URL.createObjectURL(blob || file);1

File object or Blob object
Here we will briefly talk about File objects and Blob objects:
File object is a file. For example, if I use the input type="file" tag to upload files, then each file inside is a File object.
Blob objects are binary data. For example, objects created through new Blob() are Blob objects. For another example, in XMLHttpRequest, if the responseType is specified as blob, the return value is also a blob object.
*Note
Every time createObjectURL is called, a new URL object is created. Even if you have already created a URL for the same file. If you no longer need this object, to release it, you need to use the URL.revokeObjectURL() method . When the page is closed, the browser will automatically release it, but for optimal performance and memory usage, it should be released when it is ensured that it is no longer needed.

URL.revokeObjectURL

# The ##URL.revokeObjectURL() method will release an object URL created through URL.createObjectURL(). When you have used this object URL, then let the browser know that this URL no longer needs to point to the corresponding file. When, you need to call this method.

The specific meaning is that an object URL can be used to access the specified file, but I may only need to access it once. Once it has been accessed, the object URL will If it is no longer needed, it will be released. After it is released, the object URL will no longer point to the specified file.
For example, for a picture, I created an object URL, and then through this object URL, my page This picture is loaded in. Since it has been loaded and there is no need to load this picture again, then I will release the object URL, and then this URL will no longer point to this picture.

window. URL.revokeObjectURL(objectURL);1


Download file method

var funDownload = function (content, filename) {
    var eleLink = document.createElement('a');
    eleLink.download = filename;
    eleLink.style.display = 'none';    // 字符内容转变成blob地址
    var blob = new Blob([content]);
    eleLink.href = URL.createObjectURL(blob);    // 触发点击
    document.body.appendChild(eleLink);
    eleLink.click();    // 然后移除
    document.body.removeChild(eleLink);
};

Related recommendations:

htmlBrowser displays garbled code_html/css_WEB-ITnose

The above is the detailed content of How to create html browser export and download using JS. 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

Undress AI Tool

Undress AI Tool

Undress images for free

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.

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 Article

RimWorld Odyssey How to Fish
1 months ago By Jack chen
Can I have two Alipay accounts?
1 months ago By 下次还敢
Beginner's Guide to RimWorld: Odyssey
1 months ago By Jack chen
PHP Variable Scope Explained
3 weeks ago By 百草

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)

Hot Topics

PHP Tutorial
1506
276
The latest version of the European Exchange app download and installation address 2025 version The latest version of the European Exchange app download and installation address 2025 version Aug 07, 2025 pm 09:48 PM

The European Exchange is a world-leading digital asset service platform, providing users with diverse digital product trading and financial services. Its official application is designed with convenient operation and is committed to creating a safe and stable trading environment for users.

Binance Binance Exchange's latest login portal Binance Binance Exchange's latest login portal Aug 08, 2025 pm 10:12 PM

First, download the Binance App through the official channel. 1. Click the official download link provided in the article to download. When encountering the browser security prompt, select "Still to download"; 2. After the download is completed, find the installation package in the notification bar or file manager, click to start the installation and allow the system to authorize it; 3. After the installation is successful, click the desktop icon to open the application, complete the registration and log in and enable secondary verification to ensure account security. The entire process needs to keep the network stable, and it is important to avoid using unofficial channels to ensure the security of assets.

What are the virtual currency trading apps?_The top ten recommended official virtual currency trading apps in 2025 What are the virtual currency trading apps?_The top ten recommended official virtual currency trading apps in 2025 Aug 08, 2025 pm 06:42 PM

1. Binance is known for its huge transaction volume and rich trading pairs. It provides diversified trading models and perfect ecosystems. It also ensures the security of user assets through SAFU funds and multiple security technologies and attaches great importance to compliant operations; 2. OKX Ouyi provides a wide range of digital asset trading services and unified trading account models, actively deploys the Web3 field, and improves transaction security and experience through strict risk control and user education; 3. gate.io Sesame opens the door and has good currency speed and rich currency, provides diversified trading tools and value-added services, adopts multiple security verification mechanisms and adheres to the transparency of asset reserves to enhance user trust; 4. Huobi provides one-stop digital asset services with deep industry accumulation, with strong transaction depth and

okex official website trading platform app 6.131.0 okex official latest app installation and registration okex official website trading platform app 6.131.0 okex official latest app installation and registration Aug 08, 2025 pm 06:45 PM

okex is a comprehensive, safe and reliable digital asset trading platform. Its core advantages are: 1. Provide a variety of trading products such as spot, contracts, options; 2. Integrate Web3 chakra, supports NFT, GameFi and DApps, and realizes one-stop digital asset management; 3. Use monthly Merkel Tree Reserve Certificate and Hot and Hot chakra separation technology to ensure asset security; 4. The interface is simple and smooth, and is equipped with professional tools and 7x24-hour multi-language customer service; 5. Launch financial services such as "earning money" to support asset appreciation. Users can download the APP through the official website www.okx.com, and follow the steps to complete the installation, registration, verification code input, strong password setting, identity authentication (KYC) to unlock a higher amount. It is recommended to bind Google Verifier.

Coinan Exchange official website mobile version entrance Binance Exchange. Official website app. Installation entrance Coinan Exchange official website mobile version entrance Binance Exchange. Official website app. Installation entrance Aug 08, 2025 pm 07:36 PM

1. Bien is the world's leading digital asset trading platform, providing one-stop services such as spot, derivatives trading and asset management; 2. Its official website provides a secure download portal, and users need to download the App through official channels and complete installation and trust settings according to the system type; 3. The platform has bank-level security protection, and uses multiple identity verification and SAFU funds to ensure asset security; 4. It has world-leading liquidity and supports efficient transaction execution; 5. It provides 7x24-hour multi-language customer service and a simple and easy-to-use interface to ensure users have the ultimate experience.

The latest Chinese version of the official European exchange app download. Download portal The latest Chinese version of the official European exchange app download. Download portal Aug 07, 2025 pm 09:57 PM

The European Exchange is a world-leading digital asset trading platform, providing users with currency and derivative trading services for hundreds of digital assets such as Bitcoin and Ethereum. It has won the trust of tens of millions of users around the world with its stable and reliable system, rich and diverse trading products, strict risk control system and safe and convenient operating experience.

Binance Binance official website login latest website Binance Binance exchange official page Binance Binance official website login latest website Binance Binance exchange official page Aug 08, 2025 pm 10:18 PM

First, download the Binance App through the official channel. 1. Click the link in the article to start the download. 2. Select "Download Still" to complete the installation file. 3. Find the file in the download list. During installation, 1. Click the file to start the installation. 2. Turn on the "Allow to install applications from unknown sources" on your phone. 3. After authorization, complete the installation according to the prompts. 4. Click the desktop icon to use it after success. Be sure to use a strong password and keep the mnemonic and private keys to ensure the security of the assets. Finally, download and standardize operations through official channels to ensure account security.

How to buy investment in the primary market in the currency circle? Master the channels and skills of participating in the primary market in the currency circle How to buy investment in the primary market in the currency circle? Master the channels and skills of participating in the primary market in the currency circle Aug 08, 2025 pm 06:36 PM

1. Binance Binance; 2. Ouyi OK; 3. HTX Huobi; 4. Gate.io. If you want to enter the primary market of the currency circle and look for high-potential projects, you need to understand that it is the early financing stage of new projects. Investors can purchase tokens at a low price, but with high risks. The main participating channels include: 1. Participate in decentralized issuance through the IDO platform, and you need to hold and pledge platform coins to obtain qualifications; 2. Participate in IEO, reviewed and issued by a centralized exchange, which is relatively safer; 3. Use Launchpad aggregation website to efficiently obtain multi-platform project information; 4. The threshold for private equity rounds is high, making it difficult for ordinary investors to intervene. The necessary preparations are: 1. Create a non-managed money bud such as MetaMask and safely backup mnemonics; 2. Adhere to the DYOR principle,

See all articles