Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting base URL path of iframe

Tags:

html

iframe

Is there any possible way (html, js, jquery) to change the base URL path of an iframe?

Here's what I'm trying to do: I have a webpage that has a URL-entry field and a display area. The web app takes whatever URL the user enters, and then uses a special proxy service to retrieve the webpage that the user has specified. I then render this webpage in the display area using an iframe, where I insert the html source code into the DOM of the iframe. I do not use the src attribute because I am trying to demonstrate the functionality of my proxy service, and I don't want the browser to directly render the page itself.

The html source that I insert will load in the iframe, with one caveat. None of the images or other resources that use a relative pathname work because they reference the URL of my outer webpage as the base URL. For example, if my webpage is located at www.me.com and the user tries to load www.google.com, I can render the html source for www.google.com, but the main Google image does not load because the image tries to load from www.me.com/image rather than www.google.com/image.

like image 950
laker Avatar asked Aug 10 '12 19:08

laker


People also ask

What is an iframe URL?

An iFrame, also knowns as Inline Frame, is an element that loads another HTML element inside of a web page. They are commonly used to embed specific content like external ads, videos, tags, or other interactive elements into the page.

What is base URL in URL?

The URL found in the address bar of the front page of a website is its base URL. In other words, the common prefix found while navigating inside a given website is known as the base URL. One can select a base URL from the list of those available with help of the URL general properties page.


1 Answers

At the proxy end insert this tag:

<base href="http://pathtooriginalpage" />

and that should do it.

like image 51
mplungjan Avatar answered Sep 21 '22 22:09

mplungjan