Oliver Tappin
Oliver Tappin

Reputation: 2541

Changing base URL with jQuery partially working

This code works great, it just only works on the link[href] and nothing else

$("iframe").load(function() {
    $("iframe").contents().find("script[src], img[src], link[href], a[href]").each(function(i) {
        this.href = this.href.replace(/^http:\/\/www\.mydomain\.com/, "http://www.theotherdomain.com");
    });
});

Upvotes: 0

Views: 218

Answers (1)

Johnny5
Johnny5

Reputation: 6882

This is because you try to set the href attribute this.href = ... but the only element that has href is a link. For images and scripts, you have to set the src attribute.

Upvotes: 1

Related Questions