user3330683 user3330683 - 1 month ago 12
Javascript Question

JS Bookmarklet for Searching page source for specific code

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!

Answer

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!");
}
Comments