-2

Currently using this code to show a popup if the text is found on that page. However, I wanted to show that popup on other pages if the text exists on the original page.

Example Text is on /invoice I navigate to /payment Pop up still runs

<script type="text/javascript">
  window.onload = function(){
    //If the body element of the page contains 'one hour turnaround' then trigger an alert
    if(document.body.innerHTML.toString().indexOf('one hour turnaround') > -1){
         alert("You have a ONE HOUR TURNAROUND order");
    }};
</script>
M.Heredia
  • 19
  • 1
  • 5

3 Answers3

-1

Best way is to use Ajax HTTP GET providing URL and searching in response string.

https://api.jquery.com/jquery.get/

Daniel
  • 338
  • 3
  • 13
  • This is not what the OP asked. The OP asked for how to get the pop up on other pages, not how to read the text of other pages (although, I agree; the title is rather misleading). – SirPython Aug 25 '16 at 22:32
-1

alert defaults to window.alert; the native alert method of the current window the JavaScript is running on.

So, if you want to alert in another window (that you may have opened with window.open), you'll have to use that window object:

otherWindow.alert(...);
SirPython
  • 647
  • 6
  • 19
  • He doesn't want to alert in the other window. He wants to change the `indexOf()` test to look in the innerHTML of the other window. – Barmar Aug 25 '16 at 22:32
  • `"However, I wanted to show that popup on other pages if the text exists on the original page. "` – SirPython Aug 25 '16 at 22:33
  • I interpreted that as the other page contains the Javascript that he showed, and he wants it to check if the text exists on the page that redirected to it. – Barmar Aug 25 '16 at 22:57
  • @Barmar I can understand that. Honestly, it's just a bad question. – SirPython Aug 26 '16 at 00:39
-1

For easy workaround, you can do this by saving the flag for this in the local storage and accessing on every page to check if that localstorage has value then show the popup otherwise not. after that 1hour time span should clear the localstorage. so now you dunction on the page wher you have that element is now

 window.onload = function(){
        //If the body element of the page contains 'one hour turnaround' then trigger an alert
        if(document.body.innerHTML.toString().indexOf('one hour turnaround') > -1){
              localStorage.setItem('oneHourTurnaround', "true");
               alert("You have a ONE HOUR TURNAROUND order")
               setTimeout(function(){ alert("You have a ONE HOUR TURNAROUND order"); }, 3000); // currenlty it's 3 sec
          }
        else{
            localStorage.setItem('oneHourTurnaround', "false");
        }
      }

and for all other page are

window.onload = function(){
    //If the body element of the page contains 'one hour turnaround' then trigger an alert
    if(localStorage.getItem('oneHourTurnaround')==true){
      alert("You have a ONE HOUR TURNAROUND order");
    }
 }
Nalin Aggarwal
  • 886
  • 5
  • 8