开发者

JQuery add text inside <script>

I am receiving a string via query string and I wish to add this string after a given part of text inside开发者_JS百科 <script>.

The part of the HTML code where the <script> appears is:

<span id="e641370446" class="inline"></span><script type="text/javascript">/*<![CDATA[*/eval("var a=\"697OHPkfxK+cMU-8tFgWnE4zQ3GYSIvNDpi_0Co5eVlw@yZTJmu1B.hrXqRdAsj2Lba\";var b=a.split(\"\").sort().join(\"\");var c=\"wsRdrdUVAmXmwr7wr.7lR\";var d=\"\";for(var e=0;e<c.length;e++)d+=b.charAt(a.indexOf(c.charAt(e)));document.getElementById(\"e641370446\").innerHTML=\"<a class=\\\"inline mail\\\" href=\\\"mailto:\"+d+\"?subject=[Curso] SEO Atípico%20Contato&body=Nome:%20%0D%0ATelefone:%20%0D%0AMensagem:%20%0D%0A\\\">envie um e-mail para cursos@atipico.com.br</a>\"")/*]]>*/</script>

Note that this script is encripted and also is always preceeded by a span, witch has each time a different id.

The part I wish to modify is "mailto:\"+d+\"?subject=[Curso]" inserting the query string value right after [Curso], like this:

[Curso] string

I am using "jQuery-URL-Parser" plugin to parse the url.

Besides, this script is a mailto link, so, I can make the operation only in the event of the click...

Any ideas?


Given the span ID, this is easy to solve. Use jQuery to change the DOM, not the contents of the script.

var spanId = 'e641370446', // get this from wherever
    $link = $('#' + spanId).children('a.inline.mail');
    
$link.prop('href', $link.prop('href') + '&key=value');

See for yourself: http://jsfiddle.net/mattball/E8HC5/


Edit:

I am trying to adapt your code but it is not working. In the case I have to add the string after the word "[Curso]"... any idea?

You can use something as simple as String.replace().

...
$link.prop('href', $link.prop('href').replace('[Curso]', '[Curso] some text'));
...

Demo 2: http://jsfiddle.net/mattball/f2sKa/


Solution (added by OP):

Based on your help, this is what another folk suggested:

$('a.mail').click(function (event) {
    var $this = $(this);
    var linkUrl = $this.attr('href');

    linkUrl = linkUrl.replace('[Curso]', '[Curso] some text');
    $this.attr('href', linkUrl);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜