Category Archives: JavaScript

How to write a superscript Registered ® in product name and page titles in CMS

Peoples are complaining that the products names or page titles which are registered trademarks. They are not shown superscript as the customer wishes them to be. They aren’t able to add <sup> tags in the titles.

You can simply add the following JavaScript snippet that replaces all occurrences of ® with ®.


<script type="text/javascript">
$('body :not(script)').contents().filter(function() {
   return this.nodeType === 3;
}).replaceWith(function() {
   return this.nodeValue.replace(/[®]/g, '<sup>$&</sup>');
});
</script>

JavaScript URL Redirection

If you want to set page redirection, Add the below JavaScript code in header of that page with redirection code with the URL of the page you want to redirect to.
Just FYI, Javascript redirect does not return 301 permanent redirect status code.


<script type="text/javascript">
    // JavaScript URL redirection
    window.location.replace("https://w3mind.com/new-page.html");
</script>

Redirect page after submitting contact form 7

If you want to redirect the page after the web form submission. Then you can do it easily by adding the JavaScript code in header.php Or footer.php.


<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
    location = '/thank-you/';
}, false );
</script>

Also if you want a different page for a specific contact form (ID=123) after submission, then you can add the following code.


<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
    if ( '590' == event.detail.contactFormId ) {
        location = '/quote-thank-you/';
    }
}, false );
</script>