What is the way to execute Javascript passed to innerHTML function?

Discussion in 'JavaScript' started by computerzworld, Sep 15, 2013.

  1. #1
    Hello, I am getting full HTML page as response & that HTML contains HTML code, CSS, Javascript, images etc. & I am passing this HTML to Javascript's innerHTML function. It is executing all code except my Javascript(inline & external). How can I achieve this? Please help me. Thank in advance.
     
    computerzworld, Sep 15, 2013 IP
  2. hdewantara

    hdewantara Well-Known Member

    Messages:
    540
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #2
    Hi.
    Pasting full HTML page as innerHTML doesn't seem okay, because your page will then have 2 <body>ies. That just doesn't validate, no? You might want to filter/ parse it first to specific section first before pasting. Also, some adjustments to the URL might be needed if there're external resources (CSS, javascript and images) inside that pasted page.

    Have a link I may see?
     
    hdewantara, Sep 16, 2013 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    As hdewantara said, we'd really need to see your code to weight in more about what's wrong -- though this is 2013, not 1998... begging the question "why are you using innerHTML".

    More so, why are you trying to put javascript IN your innerHTML? Doesn't sound the least bit kosher.

    Of course, if none of it's executing, are you seeing any errors in your browser's error console?
     
    deathshadow, Sep 16, 2013 IP