-2

I am trying to create a JS Bookmarklet that will search the source of whatever page I'm on for a specific code (example. "G1_Value_client") and if that exists I want it to return an alert A and if it does not exist I want it to return alert B.

I am not sure where I am going wrong. Any help would be greatly appreciated!

user3330683
  • 27
  • 1
  • 8

1 Answers1

0

Umm..Javascript Bookmarklets are written in javascript, not c#. Here's a sort of translation:

if(document.documentElement.outerHTML.indexOf("G5_CLIENT_TRACKING_ID") > -1) {
    alert("Core Site!");
} else {
    alert("Cloud Site!");
}
Runner
  • 246
  • 2
  • 9
  • What is the > -1 part saying? and is it searching for that exact match thing within the quotes or is it searching for partial match? Thanks for your help Im a total newb! – user3330683 Aug 05 '16 at 18:47
  • The function document.documentElement.outerHTML.indexOf("G5_CLIENT_TRACKING_ID") finds the element and returns the location of the element inside the HTML document. If the location is over -1 that means it exists inside the document. – Runner Aug 05 '16 at 19:00
  • Thanks, very helpful! – user3330683 Aug 05 '16 at 19:29