Cyberax Tech Web Hosting India - Web Hosting - Wordpress Theme - Debt Consolidation - Bad Credit Loans

PDA

View Full Version : How can I detect a websites page source code?


chengcj
May 8th 2006, 6:04 am
Assume my homepage has a button and a textbox. When I press the button, the textbox would show the page source code of "www.google.com" (or any other web page source code)

Of course, I haven't got the page source code before hand, or else I can just copy and paste the page source code to the textbox...

Would you please tell me how to use javascript to do that?

Thank you very much for helping me^^

May I ask a further question...

How about if I only want the first 100 charcters or the first 15 lines of the source code to be in my textbox?

How would I do that with javascript?

mad4
May 8th 2006, 6:20 am
You need to write a php script to access the third party page using fopen and echo the result to the screen (a very simple task).

Then write an ajax application to call the php script and display the resulting output into your text area.

Its pretty simple to do. :)

NetMidWest
May 8th 2006, 6:22 am
You can get the code with the JavaScript Source's source viewer (http://javascript.internet.com/page-details/source-viewer.html). How to put it in the textbox - or manipulate it otherwise - is a matter of programming.

They have lots of great snippets.

mad4
May 8th 2006, 6:30 am
You can get the code with the JavaScript Source's source viewer (http://javascript.internet.com/page-details/source-viewer.html).

A neater solution than mine. Doesn't work for me though (IE7).:)

frisby
May 8th 2006, 6:30 am
You even don't need ajax, if you allow to refresh page when someone type url.

Nutshell from brain:
$code = file_get_content("url");
<textarea><?=$code?></textarea>

Just pseudocode...

NetMidWest
May 8th 2006, 6:54 am
A neater solution than mine. Doesn't work for me though (IE7).:)
Bummer...

I have used it a few times as a template filling pagebuilder - check off menus, footers, and etc. - input the title, desc, kw, location of a content file, and via a simple cgi or php script up pops a cut and paste html page...

chengcj also mentioned Google. With the javascript, the request is by the user, not the script (in its basic form).

chengcj
May 8th 2006, 10:25 am
Thank you very much every body! But may I further ask another question...

How about if I don't want the entire source code? I would only want the first 100 characters of the source code to be in my textbox....

MrSupplier
May 8th 2006, 10:37 am
using ajax will be safer for you, but not sure if it wont be browser security restrictions for loading different domain's data...

torunforever
May 8th 2006, 6:17 pm
A neater solution than mine. Doesn't work for me though (IE7).:)

The view-source protocol was disabled in Internet Explorer 6 for Windows XP when Service Pack 2 was released. http://support.microsoft.com/default.aspx?scid=kb;en-us;904678

NetMidWest
May 8th 2006, 10:05 pm
Here is the basic implementation of what I mentioned earlier...
http //www netmidwest.com/source.html
I found it handy for seeing what was in mouseover or 0 second redirects, too.
I wonder what the logic was for disabling it.