简体   繁体   English

如何将当前页面的标题拉入 URL/src?

[英]How can I pull title of current page into a URL/src?

I'm looking to pull the title of the current page into an img src URL.我希望将当前页面的标题拉入 img src URL。

For instance:例如:

<title>booth106</title>
<img src="https://mywebsite.com/booth106/images/picture1.jpg">

Is there any code to put in so that as the title changes from page to page, so too will the booth number in the URL automatically.是否有任何代码可以输入,以便随着标题逐页更改,URL 中的展位号也会自动更改。 Is there a way to do this within a URL?有没有办法在 URL 中做到这一点?

You can do it like this.你可以这样做。 When the document is ready it will find the page title and edit the url of the picture!文档准备好后会找到页面标题并编辑图片的url!

 $('img').attr('src', 'https://www.mywebsite.com/'+ document.title +'/images/picture1.jpg');
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <img src="https://www.mywebsite.com/booth106/images/picture1.jpg" alt="my image" />

var src='https://mywebsite.com/' + document.title + '/images/picture1.jpg';
var img = document.getElementsByTagName('img')[0]; //considering you want to update the src of the first image

img.src = src;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Wordpress中将当前页面URL的一部分(最后五位数字)拉入页面内的iFrame中? - How can I pull a segment of the current page URL (last five digits) into an iFrame within the page, in Wordpress? 如何在Safari中获取当前页面的网址和标题? - How to get the url and title of the current page in safari? Angular 7:如何获取当前页面的完整URL - Angular 7 : How can i get the complete URL of the current page 如何在不重新加载当前页面的情况下加载 URL? - How can I load a URL without reloading the current page? 如何使用Angular从数组中提取特定标题? - How can I pull a specific title from an array using Angular? 在«面板»上显示当前页面的URL和标题 - Show URL and title of the current page on the «panel» 在联系表单中传递当前页面的URL和标题 - Pass current page URL and Title in contact form 如何更改当前页面标题? - How to change current page title? 如何获取基于jquery的iviewer的当前src? - How can I get the current src of jquery-based iviewer? 如何获得重定向的iframe的当前src - How can i get the current src of an iframe which is redirected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM