I want a HTML page to be displayed within a DIV using jQuery. The following code isn't working ?

$("tutorials .t").load("/path/path/cs_regular_tuts.htm")

Recommended Answers

All 11 Replies

What is tutorials? Shouldn't it have a # or . in front of it if it is a page element?

I corrected the mistake, although no html page continues to loads in the div ? Is the syntax correct ?

Maybe the path you are using isnt correct? Use your browser's console to see if there are errors, such as a 404 which means "not found".

if there is no error, check your jQuery selector to make sure its correct. "#" - used for IDs, "." - used for classes.

.load doesn't prevent me from using a site address that doesn't end in .HTML rather .com ?

I am not sure what you mean. But the example you provided above means that the content is on your site at this path from the root:


Root folder --> \path --> \path --> cs_regular_tuts.htm

I know but I'm doing a test with a .com web site, google to be exact, I will be officially loading a html file, I want to do a test with a simple .com web site.

Note that loading another html and body tag within your own may lead to rendering issues.

Pritaeas - ?

I changed my google.com example URL to a relative path html file, but I don't see anything showing in the div :(

By the way, use another website for the check: Google doesn't allow to be embedded into external frames and if you load the javascript console, you'll see the reason:

Refused to display 'https://www.google.com/?gws_rd=ssl' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'

It depends on the X-Frame-Options header. Whenever a website uses this with value SAMEORIGIN then an external frame will not work. More information here:


If you look at your browser's console (dev tools), you are going to see this error: No 'Access-Control-Allow-Origin'

if you are trying to load content from a different site, your browser isnt going to load the data unless the target site allows it. The target site controls that by adding the appropritate value for the Access-Control-Allow-Origin header

JorgeM - I don't get the error you described, instead I get the following error related to another script; SyntaxError: identifier starts immediately after numeric literal ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.