npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@moln/cross-domain-ajax

v0.1.3

Published

Cross domain AJAX via window.postmessage, for IE6/7/8. 使用 postmessage 解决IE 6/7/8 AJAX跨域问题.

Readme

低版本浏览器跨域AJAX

Cross domain AJAX via window.postmessage, for IE6/7/8.

使用 postmessage 处理IE 6/7/8 AJAX跨域问题.

工作原理

页面 a.com/a.html 直接通过ajax请求 b.com/api/b , 在低版本浏览器调用中会产生跨域问题.

假设有个 b.com/proxy.html , 由它 ajax请求 b.com/api/b 是不会有跨域问题.

解决方法就是, 使用 postmessage(低版本浏览器有 window.opener hack 方式),

a.com/a.html 要ajax请求的参数通过 postmessage 方法传到 b.com/proxy.html, 然后由 b.com/proxy.html ajax请求 b.com/api/b. 解决了低版本的跨域问题.

Installation / 安装

Using npm to install this package.

你可以使用 npm 安装

npm install @moln/cross-domain-ajax --save

Or yarn(Recommend)

或者yarn(推荐)

yarn add @moln/cross-domain-ajax -S

Usage / 使用

示例: http://127.0.0.1:8080/index.html 请求 http://127.0.0.2:8080/test.json

调用端使用示例

调用端: http://127.0.0.1:8080/index.html

关键调用代码:

var CrossAjax = require('./cross-domain-ajax');
var cajax = new CrossAjax('http://127.0.0.2:8080/cross-proxy.html'); //

cajax.ready(function () {
    cajax.ajax({
        url: 'test.json',
        success: function (data, req) {
            console.log("success", data, req);
        },
        error: function () {
            console.log("error", arguments);
        },
        complete: function () {
            console.log("complete", arguments);
        }
    });
});

代理端示例

  1. 编写请求来源限制
  2. 通过 webpack 生成 cross-proxy.html

代理端代码示例:

var cdp = require('./cross-domain-proxy');

//限制请求来源
cdp.onVerifyOrigin(function (origin) {

    console.log(origin);
    if (!/localhost:8080$/.test(origin)) {
        throw new Error('Invalid origin ' + origin);
    }
});