Reputation: 2147
I am new to HTML/Javascript
I want to open a window with javascript, and have it's HTML content loaded from an external source. I used document.write() but it does not work unless I specifically write the HTML as a parameter
Any idea how to let document.write read from an external source?
Here is what I tried.
win.document.write('<script src="window.html"></script>');
window.html
<html>
<head>
<title>test</title>
</head>
<body>
test
</body>
</html>
Upvotes: 0
Views: 1719
Reputation: 26163
If you want to get another page into a new window, then just pass the URL when you create the window...
window.open('win.html', 'popup1', 'width=400,height=200,toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0');
You may also want to consider using a jQuery UI dialog, purely for presentation purposes :)
Upvotes: 3
Reputation: 347
Document.write is not the right way.
1) Add jquery.js to your head document.
2) In the header add also this code
<script>
//document ready
$(function(){
var newDiv = $('<div></div>');
newDiv.load('window.html');
//now you have the window.html in the div content
$('body').append(newDiv);
});
or
//Open in new window
$(function(){
window.open('window.html');
});
or
//Open in iframe
var iframe = $('<iframe></iframe>');
iframe.attr('src','window.html');
$('body').append(iframe);
</script>
You must set the size of the div and the iframe.
Upvotes: 1