Javascript 如何将js脚本添加到html网页而不将其应用于子页面?

Javascript 如何将js脚本添加到html网页而不将其应用于子页面?,javascript,html,Javascript,Html,我正在使用一个名为breezy.hr的服务进行招聘,他们不允许我访问HTML,他们只允许我将js添加到他们GUI中的脚本中,它显示在网站代码中,如下所示,在正文的末尾 <script> document.title = 'Hiring - Eastern Union'; document.getElementsByTagName("a")[7].innerHTML = "<a href='/p/2066e45ed47a-commercial-rea

我正在使用一个名为breezy.hr的服务进行招聘,他们不允许我访问HTML,他们只允许我将js添加到他们GUI中的脚本中,它显示在网站代码中,如下所示,在正文的末尾

<script>
document.title = 'Hiring - Eastern Union';
document.getElementsByTagName("a")[7].innerHTML = "<a href='/p/2066e45ed47a-commercial-real-estate-mortgage-broker/apply'><button class='button apply polygot button-right bzyButtonColor'>Apply</button><h2>Commercial Real Estate Mortgage Broker</h2><ul class='meta'><li class='location'><i class='fa fa-wifi'></i><span class='polygot'>Remote OK</span></li><li class='type'><i class='fa fa-building'></i><span class='polygot'>Full-Time</span></li><li class='department'><i class='fa fa-building'></i><span>Multi-Family Group</span></li></ul><button class='button apply polygot button-full bzyButtonColor'>Apply</button><\a>";
</script>

document.title='雇用-东联';
document.getElementsByTagName(“a”)[7].innerHTML=“ApplyCommercial Real Estate Mortgage Broker
  • Remote OK
  • 全职
  • 多家庭组
问题是,当我使用inner.html命令编辑html时,它会应用于具有不同元素的子页面,因此会破坏子页面。是否有办法限制对父页面的编辑,以及仅对子页面应用内容?
(请原谅我的术语,我没有受过HTML或js方面的培训,我只是在这一个项目中使用过它)

尝试访问
窗口。位置
,并告诉脚本仅当它是主页时才运行。

使用简单的
if
语句,您可以编辑主页或子页

<script>

if(window.location == "Your home page url"){

document.title = 'Hiring - Eastern Union';
document.getElementsByTagName("a")[7].innerHTML = "<a href='/p/2066e45ed47a-commercial-real-estate-mortgage-broker/apply'><button class='button apply polygot button-right bzyButtonColor'>Apply</button><h2>Commercial Real Estate Mortgage Broker</h2><ul class='meta'><li class='location'><i class='fa fa-wifi'></i><span class='polygot'>Remote OK</span></li><li class='type'><i class='fa fa-building'></i><span class='polygot'>Full-Time</span></li><li class='department'><i class='fa fa-building'></i><span>Multi-Family Group</span></li></ul><button class='button apply polygot button-full bzyButtonColor'>Apply</button><\a>";
}
else{
console.log("sub page");
}
</script>

如果(window.location==“您的主页url”){
document.title='雇用-东联';
document.getElementsByTagName(“a”)[7].innerHTML=“ApplyCommercial Real Estate Mortgage Broker
  • Remote OK
  • 全职
  • 多家庭组
检查页面的url是否有效?这是否回答了您的问题?我如何做到这一点?告诉脚本记录/提醒位置,查看主页和子页之间的差异,并在修改脚本时进行测试。您可以看到有人复制了我的答案并对此进行了详细说明…:)谢谢else在做什么?@Antheloth,如果与语句匹配,如果不匹配,则运行else函数中的任何内容。我在else语句中使用console.log只是为了显示它是一个子页面,但您需要在其中添加子页面的脚本。