A great solution to open a link from your site's pages in a new tab

For many years now I have been looking for a solution to open a page on a new tab, by corvid, I do not know that there is a solution right at this time.
Thank goodness I found a great solution to share it here

The idea is to simply open the window through the HTML element
And send it to him. so:
You place this code inside your spade, (and of course replace the address)

$w('#html').postMessage(url)

Pay attention to add https: //

And in the HTML element you attach the following code:

<!doctype html>
<html>
<head>
<script type="text/javascript">
function init () {
  window.onmessage = (event) => {
    if (event.data) {      insertMessage(event.data);
    }
  }
}
function insertMessage(msg)  {
 window.open(msg, '_blank');
}
</script>
</head>
<body onload="init();" >
</body>
</html>

You can also define the HTML element on all site pages and use it on all site pages

evyatar.israel

5 Likes

Thanks for sharing!

1 Like