Hi

I have implemented an iframe that contains several links to other pages.
I can't change the content of the iframe because it's on another server.

Here you can see an example of the code for one link in the iframe:

<a href="javascript: void(0);" onclick="openUrl('http://www.streambeam.org');" title="">Link 1</a>

Now I would want those URL's to open in a new file, so I can add a frame on top that refers back to my own site.

Now my question is:
Is this possible, without changing anything in the iframe?


Thanks in advance!

It's possible if both page and iframe have the same domain.

You could do something like this, using JQuery:

<html>

	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
	
	<script>
		//document ready
		$(function()
		{
			//inserts iframe
			$('<iframe src="page_test.htm" />').appendTo("body");
			
			//add load handler to iframe
			$("iframe").load(function()
			{
				//Get all links<a>, unbind the event onClick and set a new one
				$(this).contents().find("a").attr("onClick", "").click(function()
				{
					alert($(this).html());
				});
			});
		});
	
	</script>
	
	<body></body>
	
</html>

The iframe page is:

<html>	
		<script type="text/javascript">
			function openUrl(url)
			{
				alert(url);
				window.location = url;
			}
		</script>
	
	<body>
		<a href="JavaScript: void(0);" onClick="JavaScript: openUrl('page_test.htm');"> Click Me One</a> <br/>
		<a href="JavaScript: void(0);" onClick="JavaScript: openUrl('page_test.htm');"> Click Me Two</a> <br/>
		<a href="JavaScript: void(0);" onClick="JavaScript: openUrl('page_test.htm');"> Click Me Three</a> <br/>
	</body>
	
</html>

If your iframe is from other domain you wouldn't have access to do it, because browser security.