簡體   English   中英

如何將 js 腳本添加到 html web 頁面而不適用於子頁面?

[英]How can I add a js script to an html web page and not have it apply to subpages?

我正在使用一項服務,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>

問題是,當我使用 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並告訴腳本僅在它是主頁時運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM