2 Replies - 1482 Views - Last Post: 16 March 2013 - 02:50 AM

#1 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 17
  • View blog
  • Posts: 893
  • Joined: 06-January 09

Viewing HTML loaded into a div

Posted 15 March 2013 - 07:18 AM

Hi all,

For my current project I'm required to load the contents of a URL into a div using JQuery because we're moving away from using frames so we can start being compatible with more browsers and devices. The problem is, there doesn't seem to be a way to view the HTML that's being placed into the div. I need to make sure it's valid and doesn't contain anything extra, and I can't run it through the W3C validators if I can't get to it.

Is there any way, using JQuery or some other trick, that I could actually see the HTML I'm loading into these divs?

(And before anyone says this is a bad idea -- yes, I know it's awful. I would have just rewritten everything as a new page without frames if I had the choice.).


EDIT -- Darn it, of course I find the answer with just a little more research. If it helps anybody, you can create a nifty little function that pops up your HTML as an alert, then pop it in the validators, like so:

function test_my_html( url ) {
var req = new XMLHttpRequest();
req.open("GET", url, false);
var page = req.responseText;
alert( page );

This post has been edited by Zel2008: 15 March 2013 - 07:38 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Viewing HTML loaded into a div

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: Viewing HTML loaded into a div

Posted 15 March 2013 - 08:01 AM

Do yourself a favor and use some browser-based JS debugger. It will be much cleaner than popping alerts.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 4192
  • View blog
  • Posts: 13,242
  • Joined: 08-June 10

Re: Viewing HTML loaded into a div

Posted 16 March 2013 - 02:50 AM

expanding on that, if you do an AJAX request (either in vanilla JS or in jQuery or anything other), the Browsers’ dev tools can show you the received AJAX response (and all its content).
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1