0

I am using a service, breezy.hr for hiring, and they don't give me access to the HTML, they only let me add js to a script in their GUI and it shows up in the website code as below, towards the end of the body.

<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>

The problem is that when I use the inner.html command to edit the HTML, it applies to subpages, which have different elements, and it therefor ruins the subpage. Is there a way to limit the edits to the parent page, as well as apply things just to the subpage? (excuse my terminology, I'm not trained in HTML or js, I've just been using it for this one project)

j08691
  • 204,283
  • 31
  • 260
  • 272
Antheloth
  • 113
  • 5
  • does checking the url of the page work? – DCR Jul 27 '20 at 18:08
  • Does this answer your question? [Best way to execute js only on specific page](https://stackoverflow.com/questions/9578348/best-way-to-execute-js-only-on-specific-page) – Heretic Monkey Jul 27 '20 at 18:14

2 Answers2

1

Using a simple if statement, you can edit the home page else the sub pages.

<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>
imvain2
  • 15,480
  • 1
  • 16
  • 21
  • Thanks! what is the else doing? – Antheloth Jul 27 '20 at 18:14
  • @Antheloth,if matches the statement, and when that doesn't match, it runs whatever is in the else function. I have console.log in the else statement just to show that it is a sub page, but that is where you will want to add the scripts for the sub pages. – imvain2 Jul 27 '20 at 18:17
0

Try to access window.location and tell the script to run only if it's the main page.

iAmOren
  • 2,760
  • 2
  • 11
  • 23