【JavaScript】IEの場合のdownload属性の代替

【JavaScript】IEの場合のdownload属性の代替

IEの場合、aタグのdownload属性が効かず、ファイルのダウンロードできなかったため、その代替案についての覚え書きです(Drupalネタではないです)。

download属性

Excelファイルをダウンロードできるように、以下のようなリンクを作成し、ファイルがダウンロードできることを確認していたのですが、


<a download="Test.xlsx" href="/download/Test.xlsx">Test.xlsx</a>

IEの場合、これではダウンロードできないとのことで、その対応結果を以下に記します。

JavaScriptでの対応

ググったところ、JavaScriptで画像をダウンロードしたいの記事によると、JavaScriptを使えば、IEでもリンクからファイルのダウンロードができるとのこと。

上記の記事を参考にして、以下のJavaScriptを記述。


function downloadFile(uri,fileName,id) {

    // IEはdownload属性が効かないので分岐
    if (window.navigator.msSaveOrOpenBlob) {
        let xhr = new XMLHttpRequest();
        xhr.open('GET', uri);
        xhr.responseType = 'blob';
        xhr.onloadend = function() {
            if (xhr.status !== 200) {
                return false;
            }
            window.navigator.msSaveOrOpenBlob(xhr.response, fileName);
        };
        xhr.send();
    } else {
        let link = document.getElementById(id);
        link.href = uri;
        link.download = fileName;
    }
}


HTMLは、以下のように記述を変更し、IEでもファイルをダウンロードできるようになりました。


<a id="download1" href="javascript:void(0);" onclick="downloadFile('/download/Test.xlsx','Test.xlsx','download1');">Test.xlsx</a>

カテゴリー

コメント

<a href=https://domnazelenoy.mybb.ru/viewtopic.php?id=2940#p6802>https://domnazelenoy.mybb.ru/viewtopic.php?id=2940#p6802</a>
名前
EdwardBok
<a href="http://vgronlinepharmacy.com/">viagra from usa pharmacy</a>
名前
Stevenbab
<a href=https://khabmama.ru/forum/viewtopic.php?t=258054>https://khabmama.ru/forum/viewtopic.php?t=258054</a>
名前
AbramPeero
Residing in Orange County or all coastal city near the ocean offers countless perks, but it also presents distinct challenges. One such challenge is the potential damage due to moisture and humidity to your drywall within our homes. In this article, we will investigate the importance of quick drywall repair and address the specific considerations for homeowners in OC and various coastal cities. By comprehending the risks and taking proactive measures, residents can guarantee the longevity and structural integrity of their homes.

Grasping the Impact of Moisture on Drywall
Drywall, a widely used building material utilized for interior walls and ceilings, is susceptible to moisture damage. In coastal areas, the proximity towards the ocean raises the chance because of higher humidity levels and occasional moisture intrusion from the salty air. When moisture filters into drywall, it could cause various problems, including:
Fungus and Mildew Growth: Excess moisture creates a great environment for mold and mildew to thrive, endangering indoor air quality and posing health risks.
Structural Weakness: Wet drywall undermines and loses its structural integrity, potentially ultimately causing sagging, cracks, and even collapse.
Aesthetic destruction: dampness ruin often effects in unattractive staining, bubbly, cracking color, and structure decline, lowering the visual appeal of your property.

Quick Drywall Repair: Stopping Supplemental Ruin
Repairing drywall quickly is vital to avoid beyond damage and minimize repairs expense. Delaying repairs can exacerbate established dilemmas, resulting in way more substantial and high priced makeovers. Keep in mind listed here main reasons why timely drywall repair is really important:
Mold Mitigation: protecting humidity-related issues promptly helps prevent mold growth and propagation, ensuring your loved ones's health.
Preserving Functional Consistency

: restoring battered drywall assures the steadiness and basic safety of your house, preventing interested hazards.
Reducing minor Damage: Moisture-damaged drywall may impact surrounding materials such as insulation and wooden framework. By correcting drywall quickly, you can easily prevent additional harm and associated repairs.
Cost Efficiency: Early detection and repair of drywall issues are far more cost-effective than waiting until the damage will become severe. Well timed servicing preserve you against lengthy changes and possibilities resettlement costs.

Strategies for Drywall Regular Maintenance in Seaside Locales
Residing nearby the ocean requires added care to maintain the consistency of one's drywall. Below are a few useful methods for house owners in OC and resort towns and cities:
Routine reports: Perform routine visual examinations of the drywall, making time for signs of dampness harm, such as for instance yellowing, cracking paint, or soft marks.
Taking care of moisture content: Use dehumidifiers or ac units to control in house wetness rates, specifically through wet seasons.
Maintaining Fresh air: Make sure ideal airflow in baths, kitchen sets, as well as other areas prone to dampness accumulation. Set and keep exhaust fans to eliminate excess wetness.
Frequently sustaining the Exterior: Regularly look over your home's outer, such as the roof top, drains, and windowpanes, to identify and fix any possibilities pointers of moisture breach.
Addressing pipes wetting: Fix any plumbing system leaks quickly to prevent water from oozing to the spaces and bringing about drywall impairment.
Professional help: Hire more experienced building contractors for detailed assessments and treatments to address any current or capacity drywall hassles.

Summation
In coastal aspects like Orange County, quick drywall restoration is essential to mitigate the destructive effects of dampness as well as moisture. By comprehending the potential risks connected with moisture damage and switching to enthusiastic measures, householders can also assure the longevity, security, and cosmetic selling point of the households.

I deeply admire the uncovering of this site because of its plenty of valuable knowledge and reliable content. The website.com has demonstrated to be an essential tool, supplying essential knowledge on a diverse subjects. Its thorough gathering of data has made it an indispensable instrument for investigation, acquiring knowledge, and remaining knowledgeable. I am astounded by the website's devotion to exactness and reliability, ensuring that visitors can trust the knowledge they encounter. I am eager about suggesting this website to my buddies, as it presents a one-of-a-kind opportunity to explore and obtain a wealth of information effortlessly. I encourage them to visit https://drywallpatchguys.com/drywall-repair-water-restoration-services-newport-beach-ca/ - South county orange county and explore the plethora of insights it has to provide.
https://drywallpatchguys.com/drywall-repair-water-restoration-company-in-san-clemente/ - Laguna Hills Laguna Hills drywall repair
http://divyaroshani.com/2020/12/21/3647/ - Environmental Pros of Drywall Rehabilitation over Replacing 5b42220
名前
FrancisEmela

コメントを追加

CAPTCHA
この質問はあなたが人間の訪問者であるかどうかをテストし、自動化されたスパム送信を防ぐためのものです。
画像CAPTCHA
画像内に表示されている文字列を入力してください。