Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use jQuery (just change the selector $("a") to be more specific, using an id or a class):</p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;SOMETITLE&lt;/title&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(function() { $("a").each(function() { $(this).attr("href", $(this).attr("href").replace("XXX", $("html head title").text()) ); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;a href="http://www.facebook.com/sharer.php?u=&lt;?php echo $url ?&gt;&amp;t=XXX"&gt;click&lt;/a&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>For the Update 2, change the script element:</p> <pre><code>&lt;script type="text/javascript"&gt; $('#block-header-facebook').each(function() { $(this).attr('href', $(this).attr('href').replace("link", document.title)); }); &lt;/script&gt; </code></pre> <p>By the way I do too recommend using the Ralph's server approach (use this only if you need to do it on the client).</p> <p><strong>Added Recommendation (See Ralph comment)</strong></p> <p>Change the a-tag and script to:</p> <pre><code>&lt;a id="block-header-facebook" href="http://www.facebook.com/sharer.php?u=&lt;?php echo $url ?&gt;"&gt; &lt;script type="text/javascript"&gt; $('#block-header-facebook').each(function() { $(this).attr('href', $(this).attr('href') + "&amp;amp;t=" + escape(document.title)); }); &lt;/script&gt; </code></pre> <p>Less error-prone code, and I will work the same.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload