/    Sign up×
Community /Pin to ProfileBookmark

innerHTML problem

Hello everybody,

I am using innerHTML to set the content of complete page. Due to this the links in the page fail to work. Only if I save the content in a file and then give that local url, the page gets loaded and the links are functional. Is there any way I can get the links working without saving the content in the local file.

Any help is appreciated.

Thanks,
Tapu

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@javawebdogDec 15.2008 — a bit too vague.

may we see some sample source code.
Copy linkTweet thisAlerts:
@rnd_meDec 15.2008 — perhaps using full, absolute urls in the .hrefs would help.

if not, post the code and we can give much better advise.
Copy linkTweet thisAlerts:
@ta99pu01authorDec 15.2008 — Thanks for the response.

Let me add some details of my web app.

There are basically 2 frames in my web application. I need to load dynamically the content of one frame with a webpage.

The webpage content which gets loaded dynamically, has some urls. If I copy this content in a local test.html file and also add the <base href='' />. and then load this url in one of the frame of my web application, it works fine. All the urls work fine.

But when I take this content and set it as the innerHTML of the frames in my webpage, it does display the content fine but the url are not not functional. Also when I see the view source page, it does not show the content, probably because innerHTML does not get the source.

Please let me know if I need to give any further details.
Copy linkTweet thisAlerts:
@rnd_meDec 15.2008 — again, use full, absolute URLs, and your problem will go away.
Copy linkTweet thisAlerts:
@ta99pu01authorDec 15.2008 — I am setting the innerHTML by giving :


dis_html = < this is the content of the HTML page >;

// add the base href

dis_html = dis_html.replace(/<head>/gi,"<head><base href=""+url+""/>");

//set the content to innerHTML

displayFrame.contentDocument.getElementsByTagName("html")[0].innerHTML=dis_html;

This shows the page getting displayed properly, but its links are not functional. Also the view source does not show the innerHTML content, is this the reason the links are not functional.

Is there any other way of doing it ?
Copy linkTweet thisAlerts:
@rnd_meDec 15.2008 — running displayFrame.contentDocument.getElementsByTagName("html")[0].innerHTML=dis_html; would kill the base tag in the htmlhead section...
Copy linkTweet thisAlerts:
@ta99pu01authorDec 15.2008 — Is there any other way I can set the innerHTML of the frame ?
Copy linkTweet thisAlerts:
@rnd_meDec 15.2008 — it doesn't matter how you set it, though i prefer .write for iframes...

you can also use a data URI anywhere except old IE...

you would build the uri, and simply set the .src of the frame to it.
×

Success!

Help @ta99pu01 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...