SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    One window inspecting and controlling elements in another.

    Hi folks.

    Is it possible to have a javascript read elements from one browser tab from another? What I want to do is have a simple script that refreshes a page that I don't host every second or so and if the text on it changes from a preset string then to stop refreshing. So I have one tab open running the JS that I host which is pressing refresh repeatedly on the other tab and if that changes then it stops refreshing.

    I've tried to think of a way to do this server-side (PHP) but couldn't think of one. I could make a script that reads the remote page repeatedly and if it changes then loads it, but to load it the remote page would refresh and then would probably lose the string I am after.

    Any help much appreciated! Even if just to say "nah, not possible" or something about XSS that I don't really understand...!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    JavaScript in one tab or window can only access content in another tab or window if:

    1. JavaScript on one of the pages opened the other page and
    2. Both pages come from the same domain.

    If either of those conditions is not met then no access is possible.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    JavaScript in one tab or window can only access content in another tab or window if:

    1. JavaScript on one of the pages opened the other page and
    2. Both pages come from the same domain.

    If either of those conditions is not met then no access is possible.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's not what I wanted to hear, but thanks very much for your help.

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,897
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    You could take a look at greasemonkey to create a userscript that does this for you.
    The greasemonkey wiki is a good source to get you started on writing your own script

    Note that greasemonkey is for firefox, but there similar methods available for Opera, Chrome and Safari. And also for IE7Pro (not for IE itself).
    Google for "greasemonkey" and the name of your browser to find out more
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •