I am using below JS code to open new window by populating dynamic generated code..
function OpenWindow(obj) {
var w = window.open();
var stored = $(obj).parent().find("div").html();
w.document.title = "New Window";
w.document.URL = "hello.com/dummypage.html"; //how to assign the url to the newly opened window
$(w.document.body).html(stored);
return false;
}
Relative urls used in this document say for img src
, in this document is not working.
<tr><td colspan='2' align='center'><img id='imglegend' src='/images/Legend.jpg'></td></tr>
EDIT:
I populate the content dynamically using javascript, just need a valid url in the brower window, to make my hyperlinks & image source ref to work.
P.S. The page pointed out in the js code, doesn't have physical existance.
When you have a menu structure that relies on relative URLs, one wrong link in your content to your test environment would cause the entire test environment to be spidered and indexed, causing massive duplicate content issues.
The relative format allows the same website to exist on staging and production domain, or the live accessible version of your website, without having to go back in and re-code all of the URLs. This not only makes coding easier for a web developer but also serves as a time saver.
If you do a lot of testing and move content frequently between domains, then relative links are the best solution. Absolute paths are more secure, protect content, and prevent duplicate pages. The main point is that the link format you prefer should be applied to all URLs on the site.
how to assign the url to the newly opened window
You need to pass and URL to window.open()
window.open('http://www.google.com');//will open www.google.com in new window.
window.open('/relative_url'); //opens relatively(relative to current URL) specified URL
Or,
function OpenWindow(obj) {
var w = window.open();
w.location = "hello.com/dummypage.html"; //how to assign the url to the newly opened window
}
Or, You can even say,
w.location.assign("http://www.mozilla.org");
Refer Window.location
Normally you would open a window giving all the parameters in the function like:
window.open('yoururl','title','some additional parameters');
But you could do it like what you did but you used the wrong variable to add your url. It should be w.document.location.href
:
var w = window.open();
w.document.title = "New window";
w.document.location.href = "hello.com"; //how to assign the url to the newly opened window
$(w.document.body).html(stored);
return false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With