Jump to content
xisto Community
Sign in to follow this  
Mordent

Manipulating External Sites With Javascript? Is it possible?

Recommended Posts

Hi all!

 

A quick question for you folks, one that I expect should be able to be answered pretty simply though I can't find a definitive answer with Google. I play an online browser based game that's mainly text-based. I'm intending to create a toolbar for said game (I already have the permission of the game's owner) that essentially simplifies a few of the tasks in the game. In short, I will have a HTML file that has a frameset in it with both my toolbar and the game's page as its frames. The target for any links in my toolbar will be the other frame, so clicking on one of them will take you to the appropriate game page while leaving the toolbar as it is. Simple enough so far?

 

The toolbar will also include various timers for actions in the game. For instance, there is a 3 minute delay between you being able to perform a certain action. Clearly it'd be fairly simple to write a piece of JavaScript that basically includes a timer in to the toolbar. You do the action, click the timer, then it counts down. When it hits zero it could pop up an alert to let you know you can do the action again. What I was wondering was whether it's possible to take the clicking on the timer stage out of the equation by altering the onClick event of the button in the game (from my toolbar) to also start the timer.

 

I've had a few attempts at this, but so far I'm having a whole heap of trouble with the basics, and I think I've found my problem: I can't seem to access any information within the game's frame from my toolbar's frame. For instance:

 

alert ( parent.gameFrame.document.title );
seems to do nothing. No popup is generated. Is my suspicion correct, and am I unable to access anything within the game's frame (as it's on an external domain) from my toolbar? If not, how would I go about it? Thanks in advance!

 

EDIT: A quick update and a link to a site that I found quite handy in some respects (link). It basically has one person stating that:

 

You can alter the *frame* contents (ie. load another document into the frame) but you can't alter the content of a document that's already in the frame if that document is from another domain.

So assuming that it's correct I now know that I can't change anything within the game page itself. Fair enough. However, given that I've abandoned the idea of removing the "click reset on timer" step from the process, I've still got a couple uses for knowing what page the game's on for my toolbar, meaning my question about why the alert code given above doesn't work still stands. Edited by Mordent (see edit history)

Share this post


Link to post
Share on other sites

Hello Mordent.You can't manipulate with the frame,content in frame can do something with the page which have the frame.For that i am sure that parent object will work.For example i have HTML page called frame.html with this source:

<a href="java script:parent.document.write('This is good website')">Click here</a>
P.S sorry you need to remove the space between java and script,this forum doesn't accept the full word
and i have HTML page example.html with the frame:
<iframe src="frame.html"></iframe>
So when you click on link "Click here" frame can change the content of example.html.About changing frame source i am not sure,but you can try to use function do get element which is frame and to something with that but i am not sure.Give a try to this code:
<iframe id="myFirstFrame" src="somebody.html"></iframe><script>document.getElementById('myFirstFrame').document.write('Lets hack somebody.html');</script>
Remember that he needs to give you all he's files for the game because one site can't get access to other site.So your scripts can only access your frames,he's website can only access he's frames.
Edited by TheDarkHacker (see edit history)

Share this post


Link to post
Share on other sites

Hello Mordent.You can't manipulate with the frame,content in frame can do something with the page which have the frame.For that i am sure that parent object will work.For example i have HTML page called frame.html with this source:

<a href="java script:parent.document.write('This is good website')">Click here</a>
P.S sorry you need to remove the space between java and script,this forum doesn't accept the full word
and i have HTML page example.html with the frame:
<iframe src="frame.html"></iframe>
So when you click on link "Click here" frame can change the content of example.html.
Yup, a bit of testing and a chunk more time on Google led me to the same conclusion as the "can't manipulate with the frame" bit. I've worked with frames before, but only when altering or reading a value that's on another page that I've written, never on someone else's.

About changing frame source i am not sure,but you can try to use function do get element which is frame and to something with that but i am not sure.Give a try to this code:

<iframe id="myFirstFrame" src="somebody.html"></iframe>   <script>   document.getElementById('myFirstFrame').document.write('Lets hack somebody.html');   </script>
This is roughly the approach I've been using to try and do it (though I've been trying to read the title of the page more than anything). So far it hasn't worked, so it seems that as well as not being able to manipulate anything that's in a frame that isn't on your domain you also can't read any values there.

Remember that he needs to give you all he's files for the game because one site can't get access to other site.So your scripts can only access your frames,he's website can only access he's frames.

This bit doesn't quite make sense to me. How does having access to the HTML (bearing in mind that I can simply view the source needed to work out what values I'd like to read) make any real difference? Other than actually running the game via my domain (namely copying any game source code and essentially cloning the game), which clearly isn't really a feasible option, I can't really see what you mean by this.
So, overall, it looks like it's impossible to either read from or write to a site that's not hosted at the same domain as yours using frames and JavaScript. Anyone got any other suggestions as to how to do it, or is it impossible?

One option that I am exploring is trying to get the toolbar made official, namely hosted by the owner of the site so that I can access various other parts of it. Not had any feedback on this yet, but for now I'm working on the grounds that it's not going to happen.

Share this post


Link to post
Share on other sites

This bit doesn't quite make sense to me. How does having access to the HTML (bearing in mind that I can simply view the source needed to work out what values I'd like to read) make any real difference? Other than actually running the game via my domain (namely copying any game source code and essentially cloning the game), which clearly isn't really a feasible option, I can't really see what you mean by this.

Well make one page and write this code:
<script>parent.document.title=".tk Title Hacked";</script>
Then host it to your hosting company and open dot.tk website which makes your URL shorter for free.This is how it works:
1.You write full and your new URL
2.Website is checking for correct information
3.Website makes new .tk domain
4.Adds one frame where source=your webpage

Write your full URL to Dot Tk and then write some short name,and write captcha letters.Then open your short URL.Title will not be updated.If you go to Java Console on Firefox you will see for your short url,few details:access is denied.That is because you can't do that.

Share this post


Link to post
Share on other sites

Well make one page and write this code:

<script>   parent.document.title=".tk Title Hacked";   </script>
Then host it to your hosting company and open dot.tk website which makes your URL shorter for free.This is how it works:

1.You write full and your new URL

2.Website is checking for correct information

3.Website makes new .tk domain

4.Adds one frame where source=your webpage

 

Write your full URL to Dot Tk and then write some short name,and write captcha letters.Then open your short URL.Title will not be updated.If you go to Java Console on Firefox you will see for your short url,few details:access is denied.That is because you can't do that.

Hmmm...I think I see where you're going with this, but based off of the wording you've used I'm not sure. Time for a quick check:

I create a page with the data in the code block above (not sure why that's needed, but anyway...)

I go to http://www.dot.tk/en/index.html?lang=en, sign up to it and use the full URL of the game page as the "long URL", with whatever short URL I want.

I can then treat it as my domain?

If that's not the case, then I'm a little confused as to exactly what you mean. As far as I can tell, this is about the only way (assuming it works) that http://www.dot.tk/en/index.html?lang=en might actually be useful to me. I'm also fairly sure you're a bit confused as to what title I need to access.

 

My current frameset structure is as follows:

 

index.html (mine)

- toolbar.html (mine)

- http://thegamesdomain.com/ (not mine)

 

I can change the title of index.html quite simply by altering it directly, or via JavaScript in either index.html (via document.title) or toolbar.html (via parent.document.title), though clearly I can't alter it from the game's domain as I don't have access to it. I'm more interested, now, in reading the title of http://thegamesdomain.com/ (not actually the url of the site, by the way :P) so that I can show different information in toolbar.html based on what page of the game I'm on (each page has a different title).

 

Hope this clears things up.

Share this post


Link to post
Share on other sites

You could use one of most used libraries called AJAX which works with JavaScript.You will need installed PHP on your server.AJAX can use PHP or what programming language you want to get response.So AJAX is connecting JavaScript with PHP.AJAX can send and request data from PHP...Get your code from http://forums.xisto.com/no_longer_exists/ and make new file called ajax.js with the same code.Now make new page called a.html and add this code:

<script src="ajax.js"></script><script>function sendRequest() {								new Ajax.Request("get.php",										{										method: 'post',										onComplete: pak										});								}function pak(es){document.getElementById('kom').innerHTML=es.responseText;sendRequest();}sendRequest();</script><div id="kom"></div>
Now make get.php with this code:
<?phpecho file_get_contents('http://mywebsite.com;;?>
So this will add the all page in the div,what you want to do with the page you can do that.Try to get title from the DIV.

Share this post


Link to post
Share on other sites

....Try to get title from the DIV.

Nope, nothing. I reckon the problem with that method is that the file_get_contents returns nothing (I'm not sure, but it doesn't look like you can do anything cross-site, same as with JavaScript?).

 

Cheers for the suggestion, though. Any others?

 

EDIT: I have a related question posted up here, though thought it best to keep them separate and in separate topics.

Edited by Mordent (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.