2

window.location = "testCall"モバイルデバイスのパラメータをバイパスするイベントを生成するには、偽の呼び出しを行う必要があります。ネイティブとして機能しますが、NotFound例外を却下するか、主に偽のwindow.location呼び出しを却下する必要があります。可能?ありがとうございました

4

1 に答える 1

5
Object.getOwnPropertyDescriptor(window, 'location').configurable === false

ChromeとSafariで(そして私は他のブラウザで推測します)。したがって、ネイティブの動作を変更することはできないようです。

通常のEcmaScript5プロパティとして動作し、次のようconfigurableに設定されてtrueいる場合は、次のようになります。

var descriptor = Object.getOwnPropertyDescriptor(window, 'location');
var setter = descriptor.set; // Doesn't exist although it should in spirit of ES5

descriptor.set = function (newLocation) {
    try {
        setter(newLocation);
    } catch (e) {
        console.log('Location error: ', newLocation, e);
    }
};

// The line below will throw exception in real browser :(
// TypeError: Cannot redefine property: location
Object.defineProperty(window, 'location', descriptor);

ブラウザベンダーがすべての魔法のプロパティとオブジェクトを標準のEcmaScriptメカニズムに移行することを願っていますが、現時点では運が悪いです。

于 2012-05-04T13:06:14.250 に答える