Problem

This jQuery error message is caused by loading the cross domain content.

Error: [Exception... "Access to restricted URI denied"  
code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)"

It’s means you are loading some content that are not belong to or located at your site (different domain name). See this jQuery example to load the cross domain (yahoo.com) content on demand.

<html>
<head>
 
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<style type="text/css">
	#content{
		border:1px solid blue;
		margin:16px;
		padding:16px;
	}
</style>
 
</head>
<body>
  <div id="msg"></div>
 
  <div id="content">
  </div>
 
  <br/>
  <button id="load">Load yahoo.com</button>
 
<script type="text/javascript">
 
$('#load').click(function(){
	$('#msg').text("Loading......");
	$('#content').load("http://www.yahoo.com", function() {
 		$('#msg').text("");
	});
});
 
</script>
 
</body>
</html>

However, this will not work, when you click on the “load” button, it just do nothing but prompt a “Access to restricted URI denied” error message. Due to the JavaScript security constraints, it’s strictly not allow to load cross domain content.

Solution

Here’s a dirty workaround – Get the cross domain content with server side language. For example, create a one line php file named “proxy.php”.

proxy.php

<?php echo file_get_contents($_GET['url']);?>

In jQuery side, change the load function to

$('#load').click(function(){
	$('#msg').text("Loading......");
	$('#content').load("proxy.php?url=http://www.yahoo.com", function() {
 		$('#msg').text("");
	});
});
</script>

Now, when you clicked on the “load” button, it will load the cross domain (yahoo.com) content into your page on demand.

Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
[ Read More ] You can find more similar articles at jQuery Tutorials