Summon iframe src since url with Javascript - 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>

Related

Get the url parameter or the part of the url after the question mark (?) of an included php file

I basically have this "info.php" file included in another php file which is "main_page.php". By clicking a link in the page, the link sends a url parameter to the "info.php" file through javascript by reloading the page, giving it a new url. The "info.php" file then, for instance, becomes "info.php?student=1" which is, again, to be clear, included inside the "main_page.php" file. I've researched for solutions but what I only found are those javascripts and php scripts that gets the current url in the address bar.
Is there a way to do this, getting the new url of an included php file? If there is, then please forgive me for my dumbness and irresponsibly inadequate researching. Thank you so much.
This is what you are looking for.
$_SERVER['QUERY_STRING']
Here is the documentation
You should be able to access your URL query variables through the global $_GET array.
$_GET['student']
If not, please edit your question with some actual code like to have a better idea of what you are trying to achieve.

How to get browser's current page URL from iframe?

Ok. This might have been asked several times but my problem is slightly different. I have following page tab in my facebook application:
Facebook Page Tab
This facebook page tab has my website embedded as iframe into it. What I want is that is to get the URL of current page inside my application.
For example, if you open above link you see facebook URL in your browser(obviously) address bar. In my iframe I just want to retrieve the URL of the parent page in which it is embedded.
I know same-origin policies in Javascript don't allow playing with cross-domain parent page's markup using javascript but I just want to retrieve the parent page URL, thats it.
Is that possible in ANY way?
Any way to access the address bar URL in my PHP application?
Thanks.
You probably don’t need the “actual URL”, but only the page id, I assume …? That you can get by decoding the signed_request parameter that gets POSTed to your app on initial load into the iframe.
How to “decode” it is described here, https://developers.facebook.com/docs/facebook-login/using-login-with-games#parsingsr
If you’re using the PHP SDK, that has a method already that does this for you.
You can use this to access it in JavaScript:
top.location.href
"top" is better than "parent". Because if your iframe is itself in another iframe then parent will return that iframe's location. "top" will return the highest location.
This will be a tough one, because CORS forbids to access the outside frame:
The referrer doesn't help very much either.
If you want to use the signed_request, and want to send custom data/parameters to your app, have a look at https://developers.facebook.com/docs/appsonfacebook/pagetabs#integrating
You can then fill the app_data parameter, and decode that in your app.
Try one of these:
parent.document.location
parent.window.document.location
parent.window.location
parent.document.location.href
I'm not sure if this will work on facebook though

Get domain of Javascript file

So I have a site at http://mysite.com/ and I have a Javascript file on a CDN, the Javascript file could be at http://cdn1.mysite.com/ or http://cdn2.mysite.com/, I need to get the value of the hostname the javascript file is on. Is there any way to do this? I cannot modify the embed code of the javascript file to add a custom ID or add an additional variable on mainsite.com.
The reasons why I need this are far too complicated for one post =)
You can get all the scripts you are loading in your page and search by name for the right one
Here is your example
If you know the index of the embedded <script> inside document.getElementsByTagName('script') you may read the src-attribute of the <script> and extract the hostname from that src.

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.

Problems of different domain with flash

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"

Categories

Resources