0

こんにちは私は通常、このコードを使用してページ内のテキストを置き換えます

    $(window).load(function() {
var html = document.body.innerHTML;
html = html.replace( /Any Text/g, '???' );
document.body.innerHTML = html;
});

私が抱えている問題は、「任意のテキスト」の代わりにURLを挿入できないことです...私の質問は、これをどのように行うかです:

$(window).load(function() {
    var html = document.body.innerHTML;
    html = html.replace( /http://subd.url.com/index.php?page=category/items/392/???/all/-1/-1/%20/%20/%20//g, 'http://www.newurl.com/foro/' );
    document.body.innerHTML = html;
    });

ありがとう、

また、このようなIDを使用する方が良いことも知っています..

  $(window).load(function() {
    $("#stID").attr("href", "http://www.newurl.com/foro/");
    }); 

でも今回は体全体を見なければなりません。

jqueryが実行されているので、誰かがjqueryでそれを行う方法を知っていれば、jqueryを開いています。ありがとう

4

2 に答える 2

0

\ などの特殊文字をエスケープします。

html = html.replace( /http\:\/\/subd.url.com\/index.php?page=category\/items\/392\/???\/all\/-1\/-1\/%20\/%20\/%20\//g, 'http://www.newurl.com/foro/' );

これにより、ページ上のすべてのリンクが同じリンク先リンクに置き換えられます。

[].map.call(document.getElementsByTagName('a'), function(a){a.href = 'http://mysite.com'})
于 2013-08-13T22:16:24.253 に答える
0

何を見つけて置き換えようとしているのかがはっきりしているとは思いませんが、額面どおり、正確な URL を別の URL に置き換えたいように見えるので、これを行うことができます ( jQuery):

$(document).ready(function() {
  $('a').each(function() {
    var href = $(this).attr('href');
    if (href=="http://subd.url.com/index.php?page=category/items/392/???/all/-1/-1/%20/%20/%20/")
      $(this).attr("href","http://www.newurl.com/foro/");
  });
});
于 2013-08-13T22:25:34.380 に答える