Jump to content

Recommended Posts

PHP, HTML, and javaScript are entirely separate languages.  Don't get them confused.  It doesn't matter which language generated the page if all you care about is the HTML source.

 

That being said, if someone wants to view the HTML source of your page, they have to press ctrl+U.  That's all.  Do it right now.

 

If you really want it to show up in a textbox, I'm sure that you can use some variant of the innerHTML attribute on the entire document, then stick that into a textarea.  I wouldn't recommend that though, it might screw up some browsers.  The "view source" menu option built into all browsers is enough.

 

-Dan

well my site administrator  needs to enter a set of urls and image urls in a form. When he clicks the submit button, display.php creates a web page based on the information he entered. He wants the source code in a text area. Since i am not proficient in javascript, I would be grateful if someone could help me out with the code...

well the page is called display.php..so whatever code is on that page(php or html) needs to be converted into html(like view source)  and be displayed in a textarea field...

Again, stop confusing PHP with HTML.  PHP is a language that generates (for the most part) text output.  PHP can be used to generate novels, emails, invoices, OR html documents.  PHP doesn't care what it's generating and whatever is generated doesn't care that PHP was involved. 

 

You are not at all interested in the PHP side of this equation.  At all.  Really, you're not.  This is entirely an html/javascript question.

 

document.getElementById('idOfYourTextAreaHere').innerHTML = document.documentElement.innerHTML;

That's all you have to do.  Run that javascript at the bottom of the page (or put it into a button) and as long as you have a textarea on the page with the proper ID then it will be filled with the page's entire content (minus the <html> and </html> tags and any doctype declarations).

 

I don't know why you need this rather than the "view source" that everyone else uses, but there's the solution.

 

-Dan

well the page is called display.php..so whatever code is on that page(php or html) needs to be converted into html(like view source)  and be displayed in a textarea field...

Again, stop confusing PHP with HTML.  PHP is a language that generates (for the most part) text output.  PHP can be used to generate novels, emails, invoices, OR html documents.  PHP doesn't care what it's generating and whatever is generated doesn't care that PHP was involved. 

 

You are not at all interested in the PHP side of this equation.  At all.  Really, you're not.  This is entirely an html/javascript question.

 

document.getElementById('idOfYourTextAreaHere').innerHTML = document.documentElement.innerHTML;

That's all you have to do.  Run that javascript at the bottom of the page (or put it into a button) and as long as you have a textarea on the page with the proper ID then it will be filled with the page's entire content (minus the <html> and </html> tags and any doctype declarations).

 

I don't know why you need this rather than the "view source" that everyone else uses, but there's the solution.

 

-Dan

 

Thanks, sometimes you have to do what your boss tells you to do...so i m breaking my head over trying to do this with javascript(unfamiliar territory for me)

I am still not able to get the html code of the current page..i am having some trouble in  calling the javascript part. Is this correct.

 

<textarea id='code'><script type='text/javascript'>document.getElementById('code').innerHTML = document.documentElement.innerHTML;</script></textarea>

 

I am still struggling a bit..here's what i tried.

<script type="text/javascript" language="javascript">
function dump()
{
    document.getElementById('debug').innerHTML = document.innerHTML;

}
</script>



<form action="#" name="form1">
<fieldset><legend>form</legend>
    <textarea rows="10" cols="20" name="textarea1" id="debug">

    </textarea>
    <button type="button" onclick="dump()">Get CODE</button>
</fieldset>
</form>

For the love of god, copy and paste.  Every time you show a new example you've subtly altered the code I've given you.  Why does your code not match the code I gave you?  the code I gave you worked.

 

Replacing your JS function with the actual line I gave you works in chrome:

 

<script type="text/javascript" language="javascript">
function dump()
{
document.getElementById('debug').innerHTML = document.documentElement.innerHTML;


}
</script>



<form action="#" name="form1">
<fieldset><legend>form</legend>
    <textarea rows="10" cols="20" name="textarea1" id="debug">

    </textarea>
    <button type="button" onclick="dump()">Get CODE</button>
</fieldset>

-Dan

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.