Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8622773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:08:02+00:00 2026-06-12T07:08:02+00:00

Lets say I have a bit of javascript code that is passed a string

  • 0

Lets say I have a bit of javascript code that is passed a string from php containing an entire html page. I write the string to the current document and then alter one of it’s containing elements. Something like this:

<script type="text/javascript">
var foo = <?php echo $html_document;?>;
document.open();
document.write(foo);
document.close();
document.getElementById("some_id_within_html_document").innerHTML = "some stuff";
</script>

This gives me my desired output, everything looks great… except when you view the source of this page. If i wanted to scrape this page later and do the same thing it displays the javascript instead of the html interpreted by the browser. Using this method how could I scrape the desired HTML instead of the javascript generating it? I have already circumvented this issue by processing the string in php instead however I am still curious if it is possible to display the interpreted HTML this way when viewing the source/scraping the page.

Edit:
Great responses across the board, I learned a lot about what is actually going on here and what practices I should stay away from. The simplest solution that would take the least effort in relation to my original problem was given by Justin Wood.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:08:03+00:00Added an answer on June 12, 2026 at 7:08 am

    don’t pass your PHP variable into the javascript. Just output the variable itself, then use javascript to edit whatever it is that you want to edit…

    <?php
    $html = "<html><head><title></title></head><body><p id='p'>Something</p></body></html>";
    
    echo $html;
    ?>
    
    <script type="text/javascript">
      document.getElementById("p").innerHTML = "blah";
    </script>
    

    Something like that should work for you.

    NOTE: I have only tested this in chrome, FF, and safari

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say i have a little bit of code I would like to repeat
Lets say I have this bit of code: <Window> <Window.Resources> <Color x:Key=MyColor A=255 R=152
Lets say I have a class A that is fairly simple like this -
I have a small question concerning css styles and javascript / jquery. Lets say
Lets say I have the following code: public class Collection implements CollectionInterface{ ElementInterface[] elementArray
Lets say we have the following code: class C t where g :: t
Lets say I have List<string> = new List<string>() {20,26,32} I want to create a
Lets say i have a a button somewhere in the code: JButton closeButton. I
Let's say i have some bit of JavaScript which will modify the DOM, perhaps
preg_match returns only the first result. lets say I have the string abcabcabc and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.