in my website I use flipbooks made with Flip PDF Professional (here's an example: https://istitutometacultura.org/progetto_babar/storie_di_babar/il_ritorno_a_casa_di_babar/microstoria.html), and I embed them into the pages using iframes (example of parent page with embedded flipbook: https://edumediateca.istitutometacultura.org/il-ritorno-a-casa-di-babar2/). These flipbooks also have the function of opening directly to a specific page, if you add "#p=X" to the end (X is the page number). Now, sometimes I need to link a specific page of the flipbook, so the flipbook link will be, for example, "https://istitutometacultura.org/progetto_babar/storie_di_babar/il_ritorno_a_casa_di_babar/microstoria.html#p=5", but this will take me to the html page, and I want the user to be taken to the page with the iframe (https://edumediateca.istitutometacultura.org/il-ritorno-a-casa-di-babar2/), not to the html file.
Since I don't want to duplicate the page just to add "#p=5" to the iframe's src, is there a way to add a value to the end of the src maybe putting it into the parent page url? (for example, if the url is https://edumediateca.istitutometacultura.org/il-ritorno-a-casa-di-babar2#p=5 the iframe's src will change from "......html" to "......html#p=5"). I don't know what to do, I really need this mechanism to work in order to publish my services... Something in Javascript or C#?
Related
So I want an iframe to take over the entirety of the page, with the ability to scroll up and down.
<iframe src="http://IFRAMEURL.COM"></iframe>
Let's say it will get embedded on another website called http://www.ANOTHERSITEURL.com/page1.php
How do I use Javascript to make my iframe containing http://IFRAMEURL.COM take up the entire page of http://www.ANOTHERSITEURL.com/page1.php
So basically it would almost look like domain masking, where you see the page for http://IFRAMEURL but the URL bar shows http://www.ANOTHERSITEURL.com/page1.php
How would I do this with a pure Javascript solution? Also consider that IFRAMEURL.COM will be different than ANOTHERSITEURL.COM
NOTE: So I need a pure javascript solution. A 3rd party user will be using this code on their site to embed my URL. I DON'T have control of anothersiteurl.com/page1.php
I just discovered that the iframe version of the Facebook Like button doesn't honor its query parameters when the iframe is created with JavaScript, rather than included directly in the document's HTML.
Please have a look at this jsFiddle that I created:
http://jsfiddle.net/qQsCC/
I generated a Like button at the URL linked above and first included the HTML exactly as it was provided. Then, I broke it down into the JavaScript code needed to create and append an identical element to the DOM.
In the "Result" window, you'll see the HTML version of the button on top, and the JavaScript-created version below. While the value of the src attribute is identical for both (as well as all other HTML attributes), the lower button doesn't appear to honor any of the parameters that I've passed, such as colorscheme or font.
Does anyone know why this is happening, or have any suggestions for how I might avoid this behavior?
The use case here is that I'm creating HTML ads that will include the iframe version of the "Like" button; a requirement is that the ad can only load 50KB of data initially, then up to 1MB after window.onload has fired. Since the "Like" button weighs in over 50KB alone, I need to construct the iframe using JavaScript after window.onload rather than just including the <iframe> element in the ad's HTML.
When you add url using HTML, html entities are automatically decoded. This doesn't nappen in javascript. So you need to decode the url before passing it to javasript eg:
like.src = 'http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2F&send=false&layout=standard&width=450&show_faces=false&action=like&colorscheme=dark&font=arial&height=35';
Hope this helps
Updated JSfidle:
http://jsfiddle.net/qQsCC/1/
For example:
function change()
{
document.getElementById('identification').href = "http://www.stackoverflow.com";
}
The associated HTML (the important bit)
Stack Overflow
<input type=button value="Change" onclick="change()" />
This will change the href in my tag to http://www.stackoverflow.com, but say I wanted to do this from a different HTML file? The JavaScript would be in the tag of the other file, but would edit the content of the first. Is this possible? If so, how?
Javascript lives only for the life of a particular page so you can't have code in one file modify another, as yet unloaded file.
Depending upon what you want the user experience to be, there are some options:
While on the first page, use some javascript to set a cookie and then when the second page loads, read that cookie and have the javascript in the second page adapt based on the cookie value. Cookies can be shared between pages on the same domain.
While on the first page, use some javascript to create a query parameter (those things after the ? in a URL that look like this ?show=true. When you load the second page, request that page by appending the ?show=true (or whatever you make up) to the end of the URL. When the second page loads, it can examine the query parameters on it's URL and decide how to modify itself. This is the simplest way of passing temporary arguments from one page to the next page.
Load the second page into an iframe (embedded into the first page) and when it's loads, your javascript can modify it (if it is served from the same domain as your main page).
Load the second page into your first page, actually inserting it into the original page either appending it or replacing some of your existing content. Then, the first page's javascript can modify the HTML from the second page once it has been inserted.
Open a new window with the new page in it. If it's on the same domain as you, then your javascript can reach into that new page and modify it.
Note: the browser tries to prevent page modifications when the two pages do not have the same origin (e.g. same domain). See a description of the same origin policy. So, if your question pertains to pages on different domains, then you will need to find a different way to solve your problem. Things like add-ons can sometimes get around the same-origin policy, but regular page javascript cannot for numerous security reasons.
Because I can't find a question that I feel matches this one enough to be closed as an exact duplicate, I'll post an answer:
Is it possible to use JavaScript in one document to change HTML in another?
Yes, assuming both windows are within the same security sandbox.
If so, how?
It's quite simple, you need to call the DOM functions from the context of the window you want to access.
a simple way to get a new window object is to call window.open
var newWin = window.open(newpage)
newWin is a window object, and therefor has a document object as well as all the other DOM elements that it may have loaded. Just like any other window, you'll need to wait for document.ready or window.onload if you're trying to interact with the elements being loaded on the page.
newWin.onload = function(){
var ident = newWin.document.getElementById('identification');
ident.href = 'http://stackoverflow.com';
};
I was trying to write a global JavaScriptfunction which overrides any HTML object (img, iframe, links and so on) before it being loaded by the page. The purpose of the overiding action was to to change the SRC and HREF of these objects using the DOM to any other link.
Unfortunately I didn't find any solution to that without firstly loading the object and only then changing it by the onload event.
My second option was to change the SRC and HREF by matching these attributes with a regular expression and replacing the resultant values. I prefer not to do so because it's slow and consumes a lot of time.
I would be glad if someone can share with his/her experience and help me solve this out.
JavaScript only works within the DOM.
You could however, load the page via AJAX, get the content and do any string manipulation on it.
If you are trying to modify items that exist in the static HTML of the page, you cannot modify them with javascript until they are successfully loaded by the browser. There is no way to modify them before that. They may or may not be visible to the viewer before you have a chance to modify them.
To solve this issue, there are a couple of options.
Put CSS style rules in the page that causes all items that you want to modify to initially be hidden and then your javascript can modify them and then show them so they will not be seen before your modification.
Don't put the items that you want to modify in the static part of your HTML page. You can either create them programmatically with javascript and insert them into the page or you can load them via ajax, modify them after loading them via ajax and then insert them into the page.
For both of these scenarios, you will have to devise a fallback plan if javascript is not enabled.
I am storing html of error pages of my site in sql table, i want to display them in a window, on the admin side, but not able to load the saved html in iframe, i am using asp.net mvc2.
its needed to save the pages, and display later to admin.
please suggest me right direction.
Thank you.
If you want it in an iframe, just write a severside script that takes this HTML and wraps it in a HTML doc dynamically: .... etc. Make this script publicly visible and pass some params to tell it what to display:
http://www.foo.com/iframescript.asp?html_display_params=saved_html
then:
<iframe src="http://www.foo.com/iframescript....
or: $('#iframeid').attr('src', 'http://www.foo.com/iframescript.asp....
you get the idea....
iframe means another url location, if you want to view something in an iframe it has to be it's own page.....
otherwise you want a normal frame.