1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Run Javascript Code Inside Another Site

Discussion in 'General Programming Chat' started by ldg2002, May 21, 2013.

  1. ldg2002

    ldg2002 Registered Member

    Joined:
    Jun 5, 2012
    Messages:
    66
    Likes Received:
    6
    Home Page:
    Hello!
    Is there any way to run a javascript inside another site through:
    Code:
    <script type='text/javascript' src="www.example.com">
    
        //various operation on the example.com site//
    
    </script>
    
    Thank you!
     
  2. lancis

    lancis Elite Member

    Joined:
    Jul 31, 2010
    Messages:
    1,632
    Likes Received:
    2,384
    Occupation:
    Entrepreneur
    Location:
    Milky Way
    Home Page:
    For yourself only yes. For example in opera/firefox you can type

    Code:
    javascript:{your code}
    into the address bar
     
  3. ldg2002

    ldg2002 Registered Member

    Joined:
    Jun 5, 2012
    Messages:
    66
    Likes Received:
    6
    Home Page:
    hey, thanks for the reply, but i don't need that.

    i have a site where i have
    Code:
    <script type='text/javascript' src="www.example.com">
    
    
        //various operation on the example.com site//
    
    
    </script>
    
    i need to run code inside this snippet above.
    Thank again
     
  4. lancis

    lancis Elite Member

    Joined:
    Jul 31, 2010
    Messages:
    1,632
    Likes Received:
    2,384
    Occupation:
    Entrepreneur
    Location:
    Milky Way
    Home Page:
    If you'll explain the purpose of what you're trying to do, it will be easier to answer.
     
  5. sirgold

    sirgold Supreme Member

    Joined:
    Jun 25, 2010
    Messages:
    1,260
    Likes Received:
    646
    Occupation:
    Busy proving the Pareto principle right
    Location:
    A hot one
    look up jsonp and how to deal with it, I suspect it'll come handy ;)
     
  6. ldg2002

    ldg2002 Registered Member

    Joined:
    Jun 5, 2012
    Messages:
    66
    Likes Received:
    6
    Home Page:
    i'm trying to do that:
    when i user visit my site i send a request to another site with:

    <script type='text/javascript' src="www.example.com"></script>

    it works. Now i need to inject some javascript code, is it possible to do?

    Thank you
     
  7. lancis

    lancis Elite Member

    Joined:
    Jul 31, 2010
    Messages:
    1,632
    Likes Received:
    2,384
    Occupation:
    Entrepreneur
    Location:
    Milky Way
    Home Page:
    First, if the site is yours, you can put any javascript code inside, and it will be executed by the user. However, javascript is a client side language - means when someone visits your site, the javascript is downloaded to that user's PC and runs locally. Anything that runs locally has no effect on your website, or that another site you speak about.

    The only thing that has some effect is AJAX queries - a small part of javascript that makes POST requests to the remote server. But you dont need javascript to make a post request, you can do that directly from PHP.

    See, its not that easy to answer without knowing the exact purpose. :) If you gave details I could just answer just yes or no, and life would be simpler.
     
  8. ldg2002

    ldg2002 Registered Member

    Joined:
    Jun 5, 2012
    Messages:
    66
    Likes Received:
    6
    Home Page:
    Thank you Lancis, the big problem is that the site is not mine, and i don't know how to inject javascript code inside.
    I'm tryin' to store cookies from site (not mine) and i'm trying to do it in javascript.
    i have a working script, but is useless if i can't inject this code into the browser of the users.
    Thanks again
     
  9. lancis

    lancis Elite Member

    Joined:
    Jul 31, 2010
    Messages:
    1,632
    Likes Received:
    2,384
    Occupation:
    Entrepreneur
    Location:
    Milky Way
    Home Page:
    Ok, now I understand better I think. You want to force visitors of another site to execute your javascript code?

    There are only 2 options I know of:
    1. Find an exploit in that site and upload your code (thats illegal, they shot you in Texas for that)
    2. Write a useful Firefox plugin and put the code there (thats illegal as well, but the Texans will forgive)