Reputation: 327
I want to load an iframe this is what I have done
document.getElementsByName('iFrameName')[0].src = url;
but it is appending the url of the file to the current url e.g. www.website.com/currentpage
so instead of the url to be www.website.com/file.html
it is now www.website.com/currentpage/file.html
How can I go about what I want
Upvotes: 0
Views: 52
Reputation: 496
You can try with Jquery instead of javascript. use the below code to set attributes in an iframe.
$('iframeName').attr('src', 'url');
if you want to load the iframe use the load method.
$('iframeId').load('currentPageUrl.html #iframeId');
Upvotes: 1
Reputation: 307
Use the setAttribute function to set the 'src' attribute with its value; Refernce Set Attribute also see the examples over there.
Element.setAttribute(name, value);
Upvotes: 1