S Mev
S Mev

Reputation: 327

Appending iframe with correct url

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

Answers (2)

Tharuka Dananjaya
Tharuka Dananjaya

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

Rajesh Verma
Rajesh Verma

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

Related Questions