<embed src="snippet.html"> - I need to insert the custom url(othersite.com/directory/something/) + "search part" of the current URL inside src attribute. I get that something like "console.log(window.location.search)" can help, but how could I connect/insert that to be inside src?
In short, my embed code output should looks like: <embed src="othersite.com/directory/something/astalavista"> , when the current URL looks like this mysite.com/info/astalavista
How should my HTML code look like?
I use Wordpress. Need HTML code. Thanks.
Try this
const loc = new URL(location.href);
const lastPath = loc.pathname.split('/').pop();
const embed = document.createElement('embed');
embed.src = `https://othersite.com/directory/something/${lastPath}`
document.body.appendChild(embed)
If you want to do it right in-place in your HTML, maybe not the best JS ever, but you can go:
some of your html...
<script>
let myUrl = "whatever"; // or echo some php variable here?
window.write(`<embed src="snippet.html/${myUrl}">`);
</script>
carry on with your html...