<embed src="snippet.html">
-我需要插入自定义url(othersite.com/directory/something/(+"搜索部分";src属性内当前URL的。我得到了类似";console.log(window.location.search(";可以帮助,但我如何将其连接/插入src?
简而言之,我的嵌入代码输出应该看起来像:<embed src="othersite.com/directory/something/astalavista">
,当当前URL看起来像mysite.com/info/astalvista 时
我的HTML代码应该是什么样子?
我使用Wordpress。需要HTML代码。谢谢
试试这个
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)
如果你想在HTML中正确地执行它,也许不是有史以来最好的JS,但你可以去:
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...