gpt4 book ai didi

javascript - 如何更改动态元标记 |但在查看源代码中不起作用

转载 作者:行者123 更新时间:2023-11-30 06:21:24 25 4
gpt4 key购买 nike

我正在使用更改我的 URL 和标题的 history.pushState 方法

window.history.pushState(null, response.pageTitle, curl);

使用这个:更改元标记描述和关键字

$('meta[name="description"]').attr('content', d.meta_disc_program);
$('meta[name="keywords"]').attr('content', d.meta_keyword_program);

网址 |元标记 |数据库动态更改标题。在页面加载或刷新时 - 通过将 URL 与数据库 URL 字段匹配来获取数据。在页面中一切正常。但是在View Source 中:URL Change But Not Show Any Meta Tag | 查看源代码

中的标题

解释更多我的问题:这是我使用的虚拟代码 - d.ProgramUrlonWeb 是(像:/b-tech-Electrical-engineering)它生成 curl (见代码)

//Change URL 

if (d.ProgramUrlonWeb) {

var ma = window.document.URL;
var res = ma.substring(0, ma.indexOf('\search-your-course'));


if (ma.indexOf('\search-your-course') != -1 && data.length > 0) {
if (d.ProgramUrlonWeb != null && d.ProgramUrlonWeb != undefined) {
//back slash in url
if (ma.indexOf('localhost') != -1) {
curl = res + 'search-your-course/programmes' + d.ProgramUrlonWeb;
}
}
}
else {
if (d.ProgramUrlonWeb != null && d.ProgramUrlonWeb != undefined) {
//forward slash in url
if (ma.indexOf('localhost') != -1 || ma.indexOf('admission.aksuniversity.ac.in') != -1) {
curl = 'search-your-course/programmes' + d.ProgramUrlonWeb;
}
}
}

//window.location.href="#";
//dynamic url
var response = {};
var stateObj = {};
response.pageTitle = d.meta_title_program;
processAjaxData(response, stateObj, ma + curl);
$('meta[name="description"]').attr('content', d.meta_disc_program);
$('meta[name="keywords"]').attr('content', d.meta_keyword_program);
}
//Change URL

下一步: processAjaxData 使用 window.history.pushState 更改页面标题和 URL。

function processAjaxData(response, stateObj, urlPath) {
var Title = response.pageTitle;
if (urlPath != "" && urlPath != undefined) {
window.history.pushState(null, response.pageTitle, curl);
document.title = Title;

}
}

on Page reload : 匹配数据库中的 URL (like :/b-tech-Electrical-engineering) 并返回数据库的所有字段,如 meta 标签和页面数据等

问题: 页面中的所有工作也可以在页面中刷新,但是当我打开查看源代码时 不工作 所有字段都是空的。那么任何解决方案? demo link我想要的。

最佳答案

谢谢,View Source 是加载数据服务器端,所以解决方案是在服务器端加载一些对 SEO 很重要的数据。我正在生成一些服务器端代码,例如对 SEO 很重要的元标题和描述以及关键字和标题标签。更改一些代码 - 在页面加载之前加载重要的 SEO 内容。通过数据库 (PHP) 匹配 URL 返回一些 SEO 标签和标题,这些标签和标题在查看源代码中有效。我希望我使用当前的策略。

关于javascript - 如何更改动态元标记 |但在查看源代码中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52830829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com