Problems of different domain with flash - javascript

I don't know which title I should use for this question.
I have a webpage (e.g. index.html) which contains flash content, url:
http://www.abc.com/travel/sg/traffic/
After I finish the webpage and upload onto the staging server, the customers said that they may need to use different domain to go to the site, e.g.
http://sg.travel.com/
The images or hyperlink do not work because of this. To handle this, I try to use the base tag as follows:
<base href="http://www.abc.com/travel/sg/traffic/" />
The images and hyperlink work. However, flash file cannot call javascript afterwards.
I would like to know how I can fix the problem.
Thanks.

Are you using relative links in the flash file? Try passing the url as a parameter and prepend the links in the flash file with them. You may also need to set up a proper crossdomain.xml to allow your flash to access other domains.

if images are the same domain as the swf, you can use relative paths.
try with
"/images/foo.png" instead of "http://www.abc.com/travel/sg/traffic/images/foo.png"

Related

Summon iframe src since url with Javascript

Good morning, I was reviewing other topics on the site but I could not find a way to solve my problem, at the end I will include some of the other topics on Stack that I was reviewing.
I am trying to create an html file that can read url parameter to invoke that url in an iframe in such HTML,
e.g.: example.com/index.html?url=https://stackoverflow.com
and this way I could load it from my site using an extractor I have.
This problem arises because I have several locations for files and I need to simplify the access to them but at the same time to have all of them in a list. When I tried to use some themes in Stack to find my solution it only caused a massive load of iframes opening and loading that never finished until it reached the limit of ram available on the server and in other cases it didn't read the url set in the parameter
Just in case, I clarify what I am looking for:
I have my site examplea.com and I want to display files through b.example.com?url=sitebackupA and so on, I just need to achieve a url parameter with javascript, thank you very much!
These are the other issues where I was checking and only the TypeForm was something close to what I need
Pass Incoming URL Parameters to iframe src with Javascript
Using Javascript for iFrame src URL
Changing iframe src with Javascript
var url = new URL(location).searchParams.get('url');
document.querySelector("iframe").src=url;
<iframe></iframe>

How Can I make my browser show files (images) that a server is sending me with download prompt?

The only solution I've found it to grab the link with getElementsByClassName then inject it into an html snippet on the page, but it looks so fake, and is also unnecessary (I don't want all the links)
I want to right click the link (one at a time) and show it to the next tab. If I right click the link the server sends me a download prompt. How can I evade this?
I think the browser decides to download a file or display it based on its MIME type.
If the server is under your control, you should make sure you supply the correct Content-Type HTTP header (e.g. you have to call a library function in PHP, and there should be a similar way to do that in other languages).
Otherwise, for a purely client-side solution in JavaScript, you can fetch the file with an XMLHttpRequest (most JavaScript toolkits have wrappers around it). Then, you can convert it to base 64, prefix the result data:image/png;base64,, and use it as the src attribute of an img element (thanks https://stackoverflow.com/a/21508186/324969).
Note that for security aspects, grabbing arbitrary files and stuffing them in a data: URL might not be safe. I don't know if any cross-site scripting or CORS attacks could be built upon this. You'll have to ask a separate question to know if the client-side solution is unsafe. For the server-side, be careful not to set the wrong content-type for user-uploaded data, or for endpoints of your service (e.g. letting the client-side send you in the request the Content-Type that it would like, as tempting as it looks, is a big no-no).
To open the image in a new tab, you can use window.open as usual, but download the image beforehand (using XMLHttpRequest) and put the data:image/png;base64,… as the URL of the new tab.
Since you can already see the images by placing their URL in an img tag, you can paint that img on a , extract a PNG from the canvas, craft a data:image/png;base64,… URL from that, and then either automatically open many tabs with these URLS, or write in your page a series of links to data: URLs.
You could also have a link to a tiny web page with just the img tag that you currently use: link text.

Hiding a PDF in html for download on link click

I am facing a situation in my application where i need to add a pdf download link on to my page, but i cannot refer to any relative or absolute path for the file, I need to host my pdf inside the html only.
Is there any way to do this, using basic HTML and JavaScript?
Details summary of situation is as below :
there is an application which owned by someone else, i am customizing if for a particular client.
we are given a provision to place some html(s) in a directory which are used in a few pages in the application.
these htmls are not used with href or include in the product application, but are picked up by the product's java code and are added in the response, thus keeping a PDF in the same folder as my HTML and providing relative URL wont work here.. and putting absolute URL is also not a solution as this needs to work across multiple environments.
You can always use data URI links:
download PDF!
Possibly together with the download attribute:
...
E.g. http://jsbin.com/gutahugoci/ (PDF is from here).
To encode in base64 use base64 -w0 my_file.pdf > my_file.pdf.b64
Disclaimer: Please notice that I said "you can use", not "you should use. This should only be a last resort thing to do for PDFs, because the HTML file will become exceedingly big and your client might ask if your are kidding them.
why don't you encode the url
/download_pdf.php?id=r4yhr4hrb4rd54hddb4
Where r4yhr4hrb4rd54hddb4 is and encoded id?

secondary source if resource is not accessible

here's the deal: I have a small onboard server on a project I'm working on, which is running kind of slow, so I thought moving images for the small website included, to external sources, like an external web server;
the problem is, I'm not sure I'll always be connected to the internet when I'll access it, maybe I'll only be in LAN.
So my question is: how can I specify a primary (external) and a secondary/backup (local) source for the images on the web page? so if the user is connected to the internet, this would take some load off the little server?
Thanks in advance, guys!
EDIT: I found the answer here:
jQuery/JavaScript to replace broken images
-it's the onerror, with an inline javascript function that reassigns the image directly!
(awesome stuff)
cheers, awesome guys from the internet that help people in need! ^^
You have the onerror that can be called when loading fails:
<img onerror="runSomeScriptThatReplacesThisImage()" ...
or:
<img onerror="this.src='yourOtherImage.jpg" ...
Just be carefull because if the onerror also fails you'll get a loop. So be sure to avoid that.
You're going to have two URL's for your images directory, e.g.
//www.remote.com/images/
~/images/
when a session starts, you could do a request to the remote server and if the request times out or you don't get a 200 response back, you can use the local URL base. I would suggest storing it in a session variable for easy access.
This can be done without using any JavaScript.
The object element can be used to display images. If the referenced image (in the data attribute) can’t be loaded, the object’s fallback content will be used. Now, if you include another object, this one will be tried. The last one should include an alternative fallback content, e.g. text describing the image (similar to the alt attribute on img).
<object type="image/png" data="http://foo.example.com/external-image.png">
<object type="image/png" data="/local-image.png">
<!-- alternative text for the image (if even the local one cannot be loaded; for accessibility; etc.) -->
</object>
</object>
I think that your best option is to retrieve the images using AJAX.
Then you can fallback to retrieving them from the slow server it the fast server fails.

ExternalInterface passing values from swf to an iFrame on the same page

On a page I have a an iFrame and a swf, I've been trying to use ExternalInterface to pass values from the swf to the iFrame, anyone ever tried this and had any luck? I won't be able to post any code until tomorrow, will update then if needed.
Thanks in adavnce.
Here is a visualization of what I need to accomplish, perhaps if it can't be done the way I said someone will have a suggestion of another way to accomplish this.
Try to target the frame. This should work with one frame on the page or you will have to change the index.
duhFrame = window.frames[0]
targetElement = duhFrame.getElementById('someIframeElement');
If this doesn't work for you then use LocalConnection and put a hidden swf on the iframe file.
LocalConnection is Global to the browser so be aware that if two browser windows are open you will get two iframes connecting on the same name and will get some funky results. So change the connection name via query string and flashvars.
Its a real hackish workaround but it will work.
[EDIT]
One more thing make sure your javascript callback function is getting called as ExternalInterface has major domain issues when running under the file structure and not in a domain(EX: clicking run in the editor ). Try uploading to your server and change your embed code to allow for it. Also dont forget to update your crossdomain.xml(s).
You cannot access iframes from outside of them. These are security reasons, and browsers will and should block such attempts.

Categories

Resources